ActionBar showAsAction="always" 不工作
ActionBar showAsAction="always" not working
我正在使用 ActionBar 和 NavigationDrawer。我在 ActionBar 上添加了 onCreateOptionMenu()。菜单项 showAction="always" 但不工作。
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="@drawable/information"
android:id="@+id/action_settings"
android:orderInCategory="100"
app:showAsAction="always"
android:title="Bilgi"/>
</menu>
Activity代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.infomenu, menu);
return true;
}
my_styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/background</item>
<item name="android:titleTextStyle">@style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
</resources>
这是我的清单:
manifest.xml
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" />
<activity
android:name=".Splash"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".login"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" />
<activity
android:name=".bildirimDetay"
android:theme="@android:style/Theme.Holo.Light.NoActionBar" />
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>
帮帮我。
在 onCreateOptionsMenu()
中提及 java 代码
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
menu.clear();
menu.add(Menu.FIRST, R.id.System_log, 4, "LOGOUT");
String get_api_key = new Database_for_Api_key(Activity_Drawer_Dashboard.this).getApi_key();
MenuItem item =
menu.add(Menu.FIRST, R.id.dashboard_nodifycation, 3, "NOTIFICATION");
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
从清单应用程序中删除主题,一切顺利:
替换:
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name"
android:theme="@style/AppTheme">
与:
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name">
将 AppBaseTheme 设置为父级="Theme.AppCompat.Light.DarkActionBar"
希望这能解决问题。
我正在使用 ActionBar 和 NavigationDrawer。我在 ActionBar 上添加了 onCreateOptionMenu()。菜单项 showAction="always" 但不工作。
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="@drawable/information"
android:id="@+id/action_settings"
android:orderInCategory="100"
app:showAsAction="always"
android:title="Bilgi"/>
</menu>
Activity代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.infomenu, menu);
return true;
}
my_styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/background</item>
<item name="android:titleTextStyle">@style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
</resources>
这是我的清单: manifest.xml
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" />
<activity
android:name=".Splash"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".login"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" />
<activity
android:name=".bildirimDetay"
android:theme="@android:style/Theme.Holo.Light.NoActionBar" />
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>
帮帮我。
在 onCreateOptionsMenu()
中提及 java 代码 @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
menu.clear();
menu.add(Menu.FIRST, R.id.System_log, 4, "LOGOUT");
String get_api_key = new Database_for_Api_key(Activity_Drawer_Dashboard.this).getApi_key();
MenuItem item =
menu.add(Menu.FIRST, R.id.dashboard_nodifycation, 3, "NOTIFICATION");
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
从清单应用程序中删除主题,一切顺利:
替换:
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name"
android:theme="@style/AppTheme">
与:
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name">
将 AppBaseTheme 设置为父级="Theme.AppCompat.Light.DarkActionBar"
希望这能解决问题。