Android 更改xml字符串数组中项目的字体颜色
我试图在弹出窗口中显示微调器。我希望每个下拉项的文本部分为绿色。更具体地说,选项如下所示: “交易类型:支付现金、会面”。我希望“交易类型”这个词是绿色的,其余的词是黑色的。 我尝试了字体颜色属性,但不起作用 字符串数组xml文件的代码:Android 更改xml字符串数组中项目的字体颜色,android,xml,android-popupwindow,Android,Xml,Android Popupwindow,我试图在弹出窗口中显示微调器。我希望每个下拉项的文本部分为绿色。更具体地说,选项如下所示: “交易类型:支付现金、会面”。我希望“交易类型”这个词是绿色的,其余的词是黑色的。 我尝试了字体颜色属性,但不起作用 字符串数组xml文件的代码: <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="payment_list"> <item><fo
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="payment_list">
<item><font color="#00ff00">Transaction Type: </font>Pay Cash, Meet Up</item>
<item><font color="#00ff00">Transaction Type: </font>Credit Card, Meet Up</item>
<item><font color="#00ff00">Transaction Type: </font>Credit Card, Ship to Me</item>
</string-array>
交易类型:支付现金、会面
交易类型:信用卡、会面
交易类型:信用卡,发货给我
弹出窗口的代码:
final Button makeoffer = (Button) view.findViewById(R.id.make_offer);
makeoffer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.offer_popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
EditText mEditText = (EditText) popupView.findViewById(R.id.payment_field);
popupView.clearFocus();
mEditText.requestFocus();
popupWindow.setFocusable(true);
popupWindow.update();
final Spinner spinner1 = (Spinner) popupView.findViewById(R.id.transaction_spinner);
spinner1.setAdapter(new ArrayAdapter<CharSequence>(getActivity(), R.layout.support_simple_spinner_dropdown_item,getActivity().getResources().getTextArray(R.array.payment_list)));
Button btnDismiss = (Button)popupView.findViewById(R.id.cancel2);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY, 0, 0);
}
});
final Button makeoffer=(Button)view.findviewbyd(R.id.make\u offer);
makeoffer.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
LayoutInflater LayoutInflater=(LayoutInflater)getActivity().getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
View popupView=LayoutFlater.充气(R.layout.offer\u弹出窗口,空);
final PopupWindow PopupWindow=新的PopupWindow(popupView、LayoutParams.MATCH_父项、LayoutParams.MATCH_父项);
EditText mEditText=(EditText)popupView.findViewById(R.id.payment_字段);
clearFocus();
mEditText.requestFocus();
popupWindow.setFocusable(真);
更新();
最终微调器微调器1=(微调器)popupView.findViewById(R.id.transaction_微调器);
spinner1.setAdapter(新的ArrayAdapter(getActivity(),R.layout.support_simple_spinner_dropdown_item,getActivity().getResources().getTextArray(R.array.payment_list));
按钮btnDismiss=(按钮)popupView.findViewById(R.id.cancel2);
btnDismiss.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
popupWindow.disclose();
}
});
popupWindow.showAtLocation(popupView,Gravity.NO_Gravity,0,0);
}
});
对于阅读本文的其他人:感谢@SirGregg为我指明了正确的方向。
我做的第一件事是将CDATA块添加到字符串数组XML文件中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="payment_list">
<item><![CDATA[<font color="#00ff00">Transaction Type: </font>]]>Pay Cash, Meet Up</item>
<item><![CDATA[<font color="#00ff00">Transaction Type: </font>]]>Credit Card, Meet Up</item>
<item><![CDATA[<font color="#00ff00">Transaction Type: </font>]]>Credit Card, Ship to Me</item>
</string-array>
</resources>
交易类型:[]>支付现金,会面
交易类型:[]>信用卡,会面
交易类型:[]>信用卡,发送给我
然后,我回到添加微调器的代码,并将其更改为:
final Spinner spinner1 = (Spinner) popupView.findViewById(R.id.transaction_spinner);
String[] array = getActivity().getResources().getStringArray(R.array.payment_list);
Spanned[] spannedStrings = new Spanned[3];
for(int i=0; i<array.length; i++){
spannedStrings[i] = Html.fromHtml(array[i]);
}
spinner1.setAdapter(new ArrayAdapter<CharSequence>(getActivity(), R.layout.support_simple_spinner_dropdown_item,spannedStrings));
final Spinner spinner1=(Spinner)popupView.findviewbyd(R.id.transaction\u Spinner);
字符串[]数组=getActivity().getResources().getStringArray(R.array.payment_列表);
跨距[]跨距串=新跨距[3];
for(int i=0;我应该帮助您。@SirGregg我添加了CDATA块,但是如何让它在微调器中实际呈现html属性呢?