Tizen应用中C语言设置Elm Label字体大小失效求助
Let’s break down why your font size setting isn’t working and fix it step by step:
1. The Immediate Problem: Incorrect String Formatting
That comma-separated expression in your elm_object_text_set call isn’t doing what you expect. In C, the expression ("<font_size=30 >%s</font_size>","TestString") only returns the last operand ("TestString"), so the <font_size> tag never actually gets passed to the label. You need to properly format the string to inject your test text into the markup template.
Use snprintf (or asprintf for dynamic memory allocation) to build the complete formatted string:
char label_text[256]; // Adjust the buffer size based on your actual text length snprintf(label_text, sizeof(label_text), "<font_size=30>%s</font_size>", "TestString");
2. Enable Markup Parsing for Elm Label
By default, Elm Label doesn’t parse HTML-like markup tags. You have to explicitly enable this functionality so the label recognizes and applies the <font_size> tag:
elm_label_markup_allowed_set(wid->label, EINA_TRUE);
Full Corrected Code Example
Here’s how your code should look after addressing both issues:
/* Label*/ wid->label = elm_label_add(wid->conform); evas_object_resize(wid->label, 200, 100); evas_object_move(wid->label, (w / 4)+115, (h / 2 )+100); evas_object_color_set(wid->label, 50, 255, 150, 255); // Enable markup parsing to recognize font size tags elm_label_markup_allowed_set(wid->label, EINA_TRUE); // Build the properly formatted text with font size styling char label_text[256]; snprintf(label_text, sizeof(label_text), "<font_size=30>%s</font_size>", "TestString"); elm_object_text_set(wid->label, label_text); evas_object_show(wid->label);
Alternative: Using Tizen’s Style API
If you prefer to avoid markup, you can set the font size directly via the label’s style property, which aligns with EFL’s native styling conventions:
elm_object_text_style_set(wid->label, "font_size=30"); elm_object_text_set(wid->label, "TestString");
This method doesn’t require enabling markup parsing, and it’s often more maintainable for consistent app styling.
内容的提问来源于stack exchange,提问作者Rifat

