dropdown menu in actionbar overlaps the actionbar - android

i have a menu in the action bar
<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.Blog.gkgyan.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:orderInCategory="101"
android:title="#string/action_share"
app:showAsAction="always"/>
<item
android:id="#+id/action_rate"
android:icon="#drawable/ic_action_important"
android:orderInCategory="102"
android:title="#string/action_rate"
app:showAsAction="always"/>
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:orderInCategory="103"
android:title="#string/action_search"
app:showAsAction="always">
<menu>
<item
android:id="#+id/menuSortNewest"
android:showAsAction="never"
android:title="Gk"/>
<item
android:id="#+id/menuSortRating"
android:showAsAction="never"
android:title="Current Affairs"/>
</menu>
</item>
<item
android:id="#+id/action_pin"
android:icon="#drawable/ic_action_make_available_offline"
android:orderInCategory="105"
android:title="#string/action_pin"
app:showAsAction="always"/>
</menu>
here is the style applied to the menu
<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="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="#android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/actionbar_background</item>
<item name="overlapAnchor">false</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
</resources>
my activity
uses
public class DetailActivity extends ActionBarActivity implements OnItemClickListener{
my problem is the dropdown menu is created however it over laps the actionbar i tried
<item name="overlapAnchor">false</item> however it doenot work
i am using
import android.support.v7.app.ActionBarActivity;
target and build versions
android:minSdkVersion="8"
android:targetSdkVersion="21" />

This is the desired behaviour according to new design guidelines. You are using appCompat so it is supposed to happen. see
Menus - Component
Update: If you still don't want the overflow menu to overlap action bar, you will have to override overflow menu style from appCompat. This might work
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light" />
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionOverflowMenuStyle">#style/OverflowMenu</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
<!-- Required for Lollipop. -->
<item name="android:overlapAnchor">false</item>
</style>
</resources>

Related

Android Menu Items not visible using `Theme.MaterialComponents.Light.NoActionBar` theme

Building a simple app with an overflow menu. The overflow menu shows up fine, however the actual MenutItems are not visible. Theme is current set to Theme.MaterialComponents.Light.NoActionBar.
But when I switch the theme to Theme.MaterialComponents.NoActionBar, it works just fine:
Here is the menu.xml:
<menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- TODO Step 9.1 - Add an item for the settings fragment -->
<item android:id="#+id/settings_dest"
android:icon="#drawable/ic_settings"
android:menuCategory="secondary"
android:title="#string/settings"
android:visible="true"
android:enabled="true"
app:showAsAction="never|withText"/>
<item android:id="#+id/settings_second"
android:icon="#drawable/ic_settings"
android:menuCategory="secondary"
android:title="Second"
android:visible="true" android:enabled="true" android:checkable="true"/>
<!-- TODO END STEP 9.1 -->
</menu>
And the style.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name = "actionMenuTextColor">#color/colorBlack</item>
</style>
Any suggestions?
Try addung your parent theme like this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
</style>

In ActionBar set four icon in android

How can i set four icons(Bookmarks,search,menu,locationdrop) in ActionBar like a image ?
Is it possible through action bar or not ? or tell me any other option .
menu_main.xml
<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.comida.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
style.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name ="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<!-- Application theme. -->
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#f26925</item>
<item name="android:logo">#android:color/transparent</item>
<item name="android:titleTextStyle">#style/CustomTextColor</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowNoTitle">true</item> <!-- Hides the Action Bar -->
<item name="android:windowFullscreen">true</item> <!-- Hides the status bar -->
</style>
<style name="CustomTextColor" parent="#android:style/TextAppearance" >
<item name="android:textColor">#0000ff</item>
</style>
</resources>
It is coming like this image using this .
You can use a Toolbar from android.support.v7.widget.Toolbar. It's support custom layout in it.
https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
https://guides.codepath.com/android/Using-the-App-ToolBar

ActionBar showing in preview but not on device

In the ApplicationManifest I have:
<application android:theme="#style/AppTheme" >
And as a style I have:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">#style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">#style/ButtonBarButton</item>
</style>
<!-- Backward-compatible version of ?android:attr/buttonBarStyle -->
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<!-- Backward-compatible version of ?android:attr/buttonBarButtonStyle -->
<style name="ButtonBarButton" />
</resources>
In preview mode, the Actionbar can be seen. However, on my device it is not. What am I missing?
Try to change parent theme of "AppTheme" to another one, i.e. "Theme.Holo.Light".
Actually actionbar is there but the menus are not visible
modify your res->menu-> main.xml
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"/>
like this
remove line
android:showAsAction="never"
My god...
In my case there was two styles.xml - in feature and installed.. both should be the same

Actionbar Actionmenu item icon not visible

This is my menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.citrusz.MainActivity" >
<item
android:id="#+id/action_offers"
android:showAsAction="ifRoom"
android:title="#string/captain_offers"/>
<item
android:id="#+id/action_events"
android:showAsAction="ifRoom"
android:title="#string/events_list"/>
<item
android:id="#+id/action_user"
android:icon="#drawable/ic_launcher"
android:showAsAction="always"
android:title="#string/action_user"/>
And this is my ActionBar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="background">#drawable/actionbar_background</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#android:color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
And I getting following output, I need Logout should be visible in ActionBar.
Try changing this
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
To
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>

Menu Items always appears in the overflow menu

This is my main.xml in menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:themomotrail="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_login"
android:orderInCategory="100"
android:title="Login"
themomotrail:showAsAction="ifRoom"/>
</menu>
This is my theme.xml
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- <item name="android:actionBarStyle">#style/MyActionBar</item> -->
<!-- Support library compatibility -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="android:actionBarTabBarStyle">#style/ActionBarTabBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/action_bar</item>
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBarTabs" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/tab_bar_background</item>
<item name="android:gravity">center</item>
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<!-- ActionBar styles -->
<style name="ActionBarTabBar" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_bar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/tab_bar_background</item>
</style>
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textSize">15sp</item>
<item name="android:padding">5dip</item>
</style>
I'm using this custom theme for the application. The problem here is, the menu item always appears in the overflow menu instead of appearing in the actionbar. What am I doing wrong ? Thanks
In the menu xml, the themomotrail namespace is wrong
You have:
xmlns:themomotrail="http://schemas.android.com/apk/res/android"
It should be:
xmlns:themomotrail="http://schemas.android.com/apk/res-auto"

Categories

Resources