gpt4 book ai didi

android - 更改 xml 字符串数组中项目的字体颜色

转载 作者:数据小太阳 更新时间:2023-10-29 02:40:06 25 4
gpt4 key购买 nike

我正在尝试在弹出窗口中显示微调器。我希望每个下拉项的部分文本为绿色。更具体地说,一个选项看起来像:“交易类型:支付现金,见面”。我希望“交易类型”字样为绿色,其余字样为黑色。我尝试了字体颜色属性,但它不起作用。

字符串数组 xml 文件的代码:

 <?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);
}
});

最佳答案

对于阅读本文的任何其他人:感谢@SirGregg 为我指明了正确的方向。我做的第一件事是将 CDATA block 添加到我的字符串数组 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));

关于android - 更改 xml 字符串数组中项目的字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30467449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com