如何改变背景颜色弹出式菜单中的android弹出式、颜色、背景、菜单中

2023-09-03 23:23:53 作者:有一些记忆挥之不去

我生成菜单从查询数据库中的每个选项。 这里是我的链接到源$ C ​​$ C: http://pastebin.com/f918BMz1 。 一切都是好的,但问题是如何改变选项菜单或弹出式菜单的背景色(从黑到白)的颜色,这可能吗?

I generate each option of menu from querying database. Here is my link to the source code: http://pastebin.com/f918BMz1 . Everything is okay, but the problem is how to change color of option menu or background color of popup menu (from black to white), Is it possible ?

final PopupMenu popupMenu = new PopupMenu(getBaseContext(),v); 
 SQLiteDatabase db = AdapterDb.getReadableDatabase(); 
 Cursor cursor = db.rawQuery(sql, null); int ctritem=0;
 if (cursor.moveToFirst()) {
 popupMenu.getMenu().add(Menu.NONE, ctritem, Menu.NONE, "ALL ITEMS"); 
 do {
  ctritem++;   
   popupMenu.getMenu().add(Menu.NONE, ctritem, Menu.NONE,   cursor.getString(0)); }
   while  (cursor.moveToNext());
 } 

感谢

推荐答案

添加弹出菜单样式UR AppTheme:

Add popupMenu style to ur AppTheme:

<style name="AppTheme" parent="android:Theme.Light">
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
</style>

manifest.xml的:

manifest.xml:

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
.............
</application>