Android 是否可以更改存储在strings.xml中的字符串名称内的特定文本颜色?
奇怪的请求,我知道,但由于特殊原因,是否可以更改strings.xml字符串中文本的颜色?例如,我希望问题文本为特定颜色。当用户单击“帮助”按钮时,文本显示在对话框片段中Android 是否可以更改存储在strings.xml中的字符串名称内的特定文本颜色?,android,xml,string,Android,Xml,String,奇怪的请求,我知道,但由于特殊原因,是否可以更改strings.xml字符串中文本的颜色?例如,我希望问题文本为特定颜色。当用户单击“帮助”按钮时,文本显示在对话框片段中 问题1?回答。问题2?回答。问题3?回答 您不应该尝试在strings.xml中更改文本颜色,您只需为TextView使用android:textColor标记,它将显示您的文本 通过DialogFragment,您可以使用任何自定义布局,在其中您可以为文本视图设置任何颜色: <string name="dial
问题1?回答。问题2?回答。问题3?回答
您不应该尝试在strings.xml中更改文本颜色,您只需为TextView使用android:textColor标记,它将显示您的文本 通过DialogFragment,您可以使用任何自定义布局,在其中您可以为文本视图设置任何颜色:
<string name="dialog_1">Dialog 1</string>
<string name="dialog_2">Dialog 2</string>
<string name="message_text">Text of your message</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="maybe">Maybe</string>
是的
Concordo com os Termos de Uso e a Política de privatiadade.
这是一个使用的例子
重要的是
单词
,那么这个文本出现在哪里呢?在TextView
中,所有文本都应该是蓝色的,还是在TextView
中,有多种颜色的混合?或者其他地方?哦,抱歉没有澄清,当用户单击“帮助”按钮时,文本显示在对话框片段中。用代码更新了帖子。看看。棒极了,你太棒了!祝你有一个好朋友。我也找到了这个。
<string name="dialog_1">Dialog 1</string>
<string name="dialog_2">Dialog 2</string>
<string name="message_text">Text of your message</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="maybe">Maybe</string>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:textColor="@color/colorPrimary" //ANY COLOUR YOU WANT
android:text="@string/message_text"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btnYes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/yes">
</Button>
<Button
android:id="@+id/btnNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/no">
</Button>
<Button
android:id="@+id/btnMaybe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/maybe">
</Button>
</LinearLayout>
public class Dialog1 extends DialogFragment implements OnClickListener {
final String LOG_TAG = "myLogs";
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getDialog().setTitle("Title!");
View v = inflater.inflate(R.layout.dialog1, null);
v.findViewById(R.id.btnYes).setOnClickListener(this);
v.findViewById(R.id.btnNo).setOnClickListener(this);
v.findViewById(R.id.btnMaybe).setOnClickListener(this);
return v;
}
public void onClick(View v) {
Log.d(LOG_TAG, "Dialog 1: " + ((Button) v).getText());
dismiss();
}
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Log.d(LOG_TAG, "Dialog 1: onDismiss");
}
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
Log.d(LOG_TAG, "Dialog 1: onCancel");
}
}