如何在Android中更改PopupMenu文本颜色?
我用Google搜索并获得了以下代码,但它在我的情况下无效。
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:popupMenuStyle">@style/popupMenuStyle</item>
<item name="android:textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="@android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@drawable/bg_trans_popup</item>
<item name="android:textColor">#FFFFFF</item>
</style>
和编程,
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(Registration.this, v);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
和菜单文件:main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_roomservices"
android:icon="@drawable/ic_launcher"
android:title="Room Services"/>
</menu>
所以,请建议我这个?
答案 0 :(得分:0)
当你获得textView或确切的视图在哪里是你的文本并设置它的颜色(或它们的颜色,当你想将它改为整个弹出菜单时),你可以动态地做到这一点。您可以使用例如:textView.setTextColor(Color.parseColor("#FFFFFF"));