我搜索了很多在谷歌和计算器中的一个环节是如何使用的风格和主题,以更改文本的颜色,但我不知道如何在code使用。
I searched a lot in google and found in stackoverflow one link how to change color of text using styles and themes but I dont know how to use in code.
<style name="TextAppearance.Widget.IconMenu.Item" parent="@android:style/TextAppearance.Small">
<item name="android:textColor">#ff0000</item>
</style>
请给我片段为更好的理解。我知道如何使用Factory.In,我们可以发现视图对象来更改菜单项的背景。是否有任何工具来获取菜单项。然后我们就可以改变菜单项的颜色?
Please give me snippet for better understanding. I know how to change the background of menuItem by using Factory.In that we can find the View object. Is there any facility to get menu Item. Then we can change the color of menuItem?
试试这个code键更改背景和文本颜色....
try this code to change background and text color....
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
getLayoutInflater().setFactory(new Factory() {
@Override
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
// set the background drawable
view.setBackgroundResource(R.drawable.my_ac_menu_background);
// set the text color
((TextView) view).setTextColor(Color.WHITE);
}
});
return view;
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
上一篇:安卓:绘制自定义边框周围列表视图?自定义、边框、视图、列表
下一篇:的NameValuePair错误&QUOT;的NameValuePair不能被解析为一个类型&QUOT;错误、类型、NameValuePair、QUOT