如何更改Android中的PopupMenu文本顏色?如何更改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>
所以,請建議我對此有何看法?
你可以通過編程來完成。 –