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>
Related
i try change background color option menu from black to white
but my code not work.i see this link too How to change background color popup menu android but its not work for me.
styles
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
</style>
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
</resources>
popup_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">
<!--///showAsAction="always" ///-->
<item android:id="#+id/action_settings" android:title="Share" showAsAction="always" />
<item android:id="#+id/action_settings1" android:title="Bluetooth" showAsAction="always" />
<item android:id="#+id/action_settings2" android:title="Exit" showAsAction="always" />
<!--/android:showAsAction="ifRoom"/-->
<item android:id="#+id/action_settings3" android:title="Share" android:showAsAction="ifRoom" />
<item android:id="#+id/action_settings4" android:title="Bluetooth" android:showAsAction="ifRoom" />
</menu>
How to change background color option menu
Have you controlled the context you passed to the constructor? When you create a PopupMenu class, please use the Activity context like this :
PopupMenu popup = new PopupMenu(this, anchorView);//Not BaseContext
Whether you use android.widget.PopupMenu or android.support.v7.widget.PopupMenu? They governed by different theme attributes :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- if using android.widget.PopupMenu -->
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<!-- if using android.support.v7.widget.PopupMenu -->
<item name="popupMenuStyle">#style/PopupMenu</item>
</style/>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
Effect like this.
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
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
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>
I have a menu.xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".StudentMarks" >
<item android:id="#+id/action_example"
android:title="#string/action_example"
android:showAsAction="withText|ifRoom"
style="#style/SelectedYear" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
The item action example has a title that represents the current year (2014).
I can see it in the action bar but i don't know how can I set the size of the year.
I would like to make it bigger.
my styles.xml files
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SelectedYear" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textSize">16sp</item>
</style>
</resources>
use this attribute in xml
android:textAppearance="?android:attr/textAppearanceLarge"
Try change your styles.xml
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textSize">20sp</item>
</style>