my actionbar is only showing the items in overflow. the androidstudio displays the items correct in the actionbar (not overflow). if i run the app on emulator or on my device the items always appears in overflow
action_bar.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_home"
android:icon="#drawable/ic_home"
app:showAsAction="always|withText"
android:title="home"/>
<item
android:id="#+id/action_share"
android:title="share"
android:icon="#android:drawable/ic_menu_share"
app:showAsAction="always"
/>
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyAppTheme.ActionBarStyle</item>
</style>
<style name="MyAppTheme.ActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyAppTheme.ActionBar.TitleTextStyle</item>
<item name="android:displayOptions">showHome</item>
</style>
<style name="MyAppTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
</style>
</resources>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar, menu);
return super.onCreateOptionsMenu(menu);
}
thanks for any help....
You are using Theme.Holo. This means that you are trying to use the native action bar. In that case, change app:showAsAction to android:showAsAction.
The following code would solve your problem.
<item
android:id="#+id/action_share"
android:icon="#android:drawable/ic_menu_share"
android:showAsAction="always"
android:title="share"/>
Note the namespace used for the attributes.
Related
Problem: I can not change a menu to lowercase letters.
I have a menu as indicated below:
<?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:id="#+id/actionOrdenesMenuPedido"
android:orderInCategory="1"
android:title="#string/item_ordenes"
android:scaleType="fitStart"
android:icon="#mipmap/ic_carrito"
app:showAsAction="always"/>
<item
android:id="#+id/tituloMenuPedido"
android:orderInCategory="2"
android:title="#string/item_orden"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:enabled="false"
app:showAsAction="always"/>
<item
android:id="#+id/actionGuardarMenuPedido"
android:orderInCategory="3"
android:title="#string/item_guardar"
android:icon="#mipmap/ic_guardar"
app:showAsAction="always"/>
<item
android:id="#+id/actionCancelarMenuPedido"
android:orderInCategory="4"
android:title="#string/btn_cancelar"
android:icon="#mipmap/ic_eliminar"
android:scaleType="fitEnd"
app:showAsAction="always"/>
</menu>
And it is invoked in the following way:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_pedido, menu);
return true;
}
And the only item that displays text keeps the letters in uppercase even though they are disabled. (android:textAllCaps="false").
Any idea how to fix this?
Try this :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
Hope it helps !
I am trying to apply a theme on my application. Everything is working fine except the menu that I am inflating with a display_menu.xml file. What I am doing wrong here?
My styles.xml
<style name="AppTheme.Dark">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:colorBackground">#color/colorBackground</item>
<item name="android:textColorSecondary">#color/textColorPrimary</item>
<item name="android:windowBackground">#color/colorBackground</item>
<item name="android:textColorSecondaryInverse">#color/textColorPrimary</item>
<item name="android:textColor">#color/textColorPrimary</item>
<item name="cardStyle">#style/CardView.Dark</item>
<item name="android:popupMenuStyle">#style/MyApp.PopupMenu</item>
</style>
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
<item name="android:textAppearanceListItem">#style/MyText</item>
</style>
<style name="MyText">
<item name="android:textColor">#color/colorAccent</item>
</style>
My display_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:id="#+id/action_refresh"
android:title="#string/action_refresh"
app:showAsAction="never" />
</menu>
I'm inflating it like
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.display_menu, menu);
return true;
}
My menu item is displaying like this:
This is the drawable I am trying to put in background:
I am trying to give the background of menu item as my colorPrimary** and text color as textColorPrimary
This Helps me
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:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
.............
</application>
I want change background of menu and set it to blue. Now background of my menu is black.How to change this?
Menu xml file :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.nabege.AboutUsActivity" >
<item
android:id="#+id/help"
android:title="#string/help" />
<item
android:id="#+id/setting"
android:title="#string/setting"/>
Java codes :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about_us, menu);
return super.onCreateOptionsMenu(menu);
}
Put the following styles in your styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary_color</item>
<!--<item name="colorPrimaryDark">#color/primary_color</item>-->
<item name="colorAccent">#color/primary_color</item>
<item name="actionBarStyle">#style/AppThemeActionBarStyle</item>
</style>
<style name="AppThemeActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#color/your_background_color</item>
</style>
Hope this helps.
Until now my Activity extended FragmentActivity and uses the ActionBarCompat. If i try to run my app on a smartphone with API level 10 (2.3.3) (or less i think) the ActionBar doesn't appear. To try to solve this problem i extended ActionBarActivity, BUT now i can't see the
items on it. I think i need to change this method:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
but i don't understand how.
This is the main:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.loris.stefano.easyroutes.MainActivity">
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/option_group_2"
android:icon="#drawable/layers"
android:showAsAction="always">
<menu>
<item
android:id="#+id/map_tipe_normal"
android:title="#string/map_type_normal"/>
<item
android:id="#+id/map_type_terrain"
android:title="#string/map_type_terrain"/>
<item
android:id="#+id/map_type_hybrid"
android:title="#string/map_type_hybrid"/>
<item
android:id="#+id/map_type_satellite"
android:title="#string/map_type_satellite"/>
<item
android:id="#+id/map_type_none"
android:title="#string/map_type_none"/>
</menu>
</item>
<item
android:id="#+id/draw_path_menu"
android:icon="#drawable/draw"
android:showAsAction="always">
<menu>
<item
android:id="#+id/merge_markers"
android:title="Merge Markers"/>
<item
android:id="#+id/draw_path"
android:title="Draw Path"/>
</menu>
</item>
<item
android:id="#+id/track_options"
android:icon="#drawable/import_map"
android:showAsAction="always">
<menu>
<item
android:id="#+id/import_track"
android:title="Import Track"/>
<item
android:id="#+id/export_track"
android:title="Export Track"/>
<item
android:id="#+id/download_track"
android:title="Download Track"/>
</menu>
</item>
I cannot figure out how to change the action bar items "onPressed" color on Android. I'm not talking about the action bar background color but about the blue over state. How can I change the color of this or at least get rid of it? For instance the App Icon with the homeAsUpIndicator.
I tried to change the action bar style and also the menu item style but nothing worked.
Thanks
EDIT
Here is my implementation so far:
My style xml:
<style name="Theme.AppTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:selectableItemBackground">#android:color/transparent</item>
<item name="android:windowEnterAnimation">#anim/fadein</item>
<item name="android:windowExitAnimation">#anim/fadeout</item>
<item name="android:actionBarItemBackground">#android:color/transparent</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbarheader</item>
<item name="android:backgroundStacked">#drawable/actionbarheader</item>
<item name="android:backgroundSplit">#drawable/actionbarheader</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="android:actionBarItemBackground">#android:color/transparent</item>
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="android:homeAsUpIndicator">#drawable/actionbarlogo</item>
<item name="android:icon">#drawable/app_icon</item>>
</style>
<style name="ActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">20sp</item>
</style>
<style name="MyActionButtonStyle" parent="#android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">#android:color/transparent</item>
</style>
Then I have a drawable for the actionbarogo:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/actionbarlogo_on" android:state_pressed="true"/>
<item android:drawable="#drawable/actionbarlogo_on" android:state_focused="true"/>
<item android:drawable="#drawable/actionbarlogo_off"/>
</selector>
My menu xml for the action bar items:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/ContactsMode"
android:icon="#drawable/actionbarcontacts"
android:title="#string/contacts"
android:orderInCategory="100"
android:showAsAction="always"
android:background="#android:color/transparent" />
</menu>
and finally, the item's drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/actionbarcontacts_on" android:state_pressed="true"/>
<item android:drawable="#drawable/actionbarcontacts_on" android:state_focused="true"/>
<item android:drawable="#drawable/actionbarcontacts_off"/>
</selector>
Here is how I create the Menu Items for the ActionBar:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
actionBar.setIcon(R.drawable.actionbarlogo);
return true;
}
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item= menu.findItem(R.id.ContactsMode);
if(ContactsButton)
item.setVisible(true);
else
item.setVisible(false);
return true;
}
To set the background for app icon together with the homeAsUpIndicator (there is a common background for these two icons) you have to set android:actionBarItemBackground item in the theme. The theme has to contain something like this (I assume that you use ActionBarSherlock):
<style name="MyTheme" parent="#style/Theme.Sherlock">
<!-- for ActionBarSherlock -->
<item name="actionBarItemBackground">#drawable/my_background</item>
<!-- for native ActionBar -->
<item name="android:actionBarItemBackground">#drawable/my_background</item>
</style>
Where the drawable drawable/my_background.xml would be a StaleListDrawable, containing something like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/my_background_pressed" />
<item
android:drawable="#drawable/my_background_normal" />
</selector>
To disable the background completely, you can set a transparent background, or value #null in the theme might also work.
The theme item android:actionBarItemBackground sets the background for app icon and homeAsUpIndicator. But it also sets the default background for menu items, overflow icon and background for title. These backgrounds can be overridden.
Menu items
To change the menu item background set a proper (android:)actionButtonStyle in the theme like this:
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
And MyActionButtonStyle will contain something like this:
<style name="MyActionButtonStyle" parent="#style/Widget.Sherlock.ActionButton">
<item name="android:background">#drawable/my_background</item>
</style>
Overflow icon
And finally, to change the overflow icon background set a properandroid:actionOverflowButtonStyle in the theme like this:
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="actionOverflowButtonStyle">#style/MyOverflowButtonStyle</item>
<item name="android:actionOverflowButtonStyle">#style/MyOverflowButtonStyle</item>
</style>
And MyOverflowButtonStyle will contain something like this:
<style name="MyOverflowButtonStyle" parent="#style/Widget.Sherlock.ActionButton.Overflow">
<item name="android:background">#drawable/my_background</item>
</style>
Fixed it. There was a parent activity changing the theme in the onCreate method...
I didn't know that you could set the theme programmatically within the activity with:
setTheme(R.style.MyTheme);