popup menu items on listView are not visible - android

I am using an image button on ListView which shows a popup menu when clicked.
But the problem is that items are not visible.
This is how menu looks.I can see white text on menu in this image but on mobile screen it is invisible.
This is styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorBackground">#color/colorPrimary</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:textColorSecondary">#fcfcfc</item>
<item name="android:actionMenuTextColor">#color/black</item>
</style>
<style name="itemTextStyle.AppTheme" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/colorPrimary</item>
</style>
<!-- LoginCreateText -->
<style name="LoginCreateText">
<item name="android:textSize">#dimen/login_buttons_text_size</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:layout_margin">2dp</item>
</style>
<!-- LoginCreateTextButton -->
<style name="LoginCreateTextButton">
<item name="android:textSize">#dimen/login_buttons_text_size</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:layout_margin">2dp</item>
<item name="android:clickable">true</item>
</style>
<style name="HintText">
<item name="android:textSize">0dp</item>
</style>
<style name="FAB">
<item name="android:layout_margin">0dp</item>
<item name="fabSize">normal</item>
<item name="rippleColor">#android:color/white</item>
<item name="backgroundTint">#color/colorAccent</item>
</style>
<style name="ListItemText">
<item name="android:textColor">#color/light_black</item>
<item name="android:textSize">#dimen/list_item_text_size</item>
<item name="android:layout_margin">2dp</item>
</style>
</resources>
This is themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Button.Login" parent="android:Widget.Button">
<item name="android:paddingLeft">18dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:textSize">#dimen/login_buttons_text_size</item>
<item name="android:layout_gravity">center</item>
<item name="android:background">#color/colorPrimary</item>
</style>
<style name="Toolbar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:itemTextAppearance">#style/itemTextStyle.AppTheme</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColorPrimary">#android:color/white</item>
</style>
<style name="CustomTheme.Dialog" parent="Theme.AppCompat.Light.Dialog"/>
</resources>
This is the menu which I am trying to display.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:popupTheme="#style/itemTextStyle.AppTheme">
<item
android:id="#+id/action_edit"
android:title="#string/action_edit" />
<item
android:id="#+id/action_delete"
android:title="#string/action_delete"/>
<item
android:id="#+id/action_assign"
android:title="#string/action_assign"
android:checkable="true"/>
<item
android:id="#+id/action_mark"
android:title="#string/action_mark"
android:enabled="false"/>
</menu>
This is layout file for Quiz Fragment.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:id="#+id/rl_fragment_quiz_lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey"
app:popupTheme="#style/itemTextStyle.AppTheme"
tools:context=".ui.fragments.QuizFragment">
<include layout="#layout/single_active_list" />
<ListView
android:id="#+id/list_view_active_lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
style="#style/FAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="showAddQuizDialog"
android:src="#drawable/ic_add_quiz"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp">
<!--app:rippleColor="#android:color/white" /> -->
</android.support.design.widget.FloatingActionButton>
</RelativeLayout>
This is the layout file of the activity in which this fragment is displayed.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Toolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Toolbar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I have tried many solutions that were asked before ( all were about toolbar menu) but none worked for me.
I defined a new style in styles.xml
<style name="itemTextStyle.AppTheme" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/colorPrimary</item>
and included it in AppTheme which didn't work.then I included it in toolbar style, menu layout, QuizFragment layout but items were still invisible.How to change the background color or item color of menu to fix this, any one will work.

Try this
style.xml
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="android:actionOverflowButtonStyle">#style/OverflowButton</item>
<item name="actionOverflowButtonStyle">#style/OverflowButton</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:dropDownListViewStyle">#style/PopupMenuListView</item>
<item name="dropDownListViewStyle">#style/PopupMenuListView</item>
<item name="actionOverflowMenuStyle">#style/OverflowMenu</item>
<item name="actionBarDivider">#null</item>
<!-- OverFlow Menu Text Color -->
<item name="android:textColor">#color/black</item>
</style>
<!-- OverFlow menu Styles -->
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:divider">#color/black</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:background">#color/white</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>
<item name="android:dropDownVerticalOffset">4.0dip</item>
</style>
and define theme for Activity in AndroidManifest.xml
<activity
android:name=".YourActivityName"
android:theme="#style/CustomActionBarTheme"/>

I am using only two themes files (for dark, and day)
Theme.MaterialComponents.DayNight.NoActionBar.Bridge
inside them, I have only items of the same name for both day and night, but in different colors. Found (after experimenting)...that this line is a game-changer in my case (same problem as yours) for title and menu to be white, while at the same time text on popup menu is black
<item name="android:textColorSecondary">#android:color/white</item>
here is the whole file, I used only this, and trying to not hard code anything.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Ch+++itche+++++" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<!-- Primary brand color. -->
<item name="android:textColorSecondary">#android:color/white</item>
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryVariant">#color/primaryDarkColor</item>
<item name="colorOnPrimary">#color/primaryLightColor</item>
<item name="colorOnSurface">#color/primaryColorWhiteDay</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
That is all,
Happy coding,
Nenad

Related

Reduce overdraw android toolbar

I have an application in which the toolbar is overdrawn several times, the cause of this is the use of an additional background, if I remove this background, the problem is solved but the color of the toolbar is black and that's not what i want, the solution i think is to override the material background color instead of adding a new one (because it has already taken a background from the material theme) but i don't know how to do it.
Toolbar:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" /> <!-- causing overdraw problem -->
</com.google.android.material.appbar.AppBarLayout>
Theme :
<style name="Theme.MyApp" parent="Base.Theme.MyApp">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/color_cape_cod</item>
<item name="colorPrimaryVariant">#color/color_mine_shaft</item>
<item name="colorOnPrimary">#color/color_white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/vivid_cerulean</item>
<item name="colorSecondaryVariant">#color/color_teal</item>
<item name="colorOnSecondary">#color/color_black</item>
<!-- background -->
<item name="android:colorBackground">#color/color_mine_shaft_dark</item>
<item name="colorOnBackground">#color/color_white</item>
<!-- surface -->
<item name="colorSurface">#color/color_black</item>
<item name="colorOnSurface">#color/color_white</item>
<!-- Customize your theme here. -->
<item name="imageTintColor">#color/color_white</item>
<item name="toolbarTextColor">#color/color_white</item>
<item name="lineHighlightColor">#color/color_tundora</item>
<item name="android:navigationBarColor">#color/color_black</item>
</style>
<style name="CustomRunButton" parent="ThemeOverlay.MaterialComponents">
<item name="colorSecondary">#color/color_raven</item>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert">
<item name="android:textColorPrimary">#color/color_white</item>
</style>
<style name="Base.Theme.MyApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="alertDialogTheme">#style/AppCompatAlertDialogStyle</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">?attr/isLightTheme</item>
</style>
<style name="BottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheetStyle</item>
</style>
<style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#android:color/transparent</item>
</style>

Unable to change the Color of the Menu option on the Android Toolbar

been trying to change the color of the menu items that appear on the Toolbar.
Here is my menu xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:title="Settings"
app:showAsAction="never"
android:orderInCategory="100"/>
<item android:id="#+id/always"
android:title="Always"
app:showAsAction="always"
android:orderInCategory="101"/>
<item android:id="#+id/never"
android:title="Never"
app:showAsAction="never"
android:orderInCategory="102"/>
<item android:id="#+id/ifroom"
android:title="If Room"
android:orderInCategory="103"
app:showAsAction="ifRoom"/>
<item android:id="#+id/always1"
android:title="Always1"
app:showAsAction="always"
android:orderInCategory="104"/>
</menu>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
</resources>
I've tried using the style options but I cannot figure out how to change the color. The actionMenuTextColor & android:actionMenuTextColor do not solve the problem. It still appears black. Which looks untidy on my blue background.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:background="#color/colorPrimary">
</android.support.v7.widget.Toolbar>
Turns out I was inheriting the wrong theme! This works for me!
Remove this line in styles.xml
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
and add this
<item name="android:textColor">#color/red</item>
<item name="android:itemBackground">#color/skyBlue</item>
Complete code :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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:textColor">#color/red</item>
<item name="android:itemBackground">#color/skyBlue</item>
</style>

Is there any possible way to style Relative Layouts using styles.xml in Android Studio?

Instead of setting the layout_toRightof, layout_toLeftof, layout_above and layout_below parameters everytime a view is created, is there a way to include it in the styles.xml file such that it becomes easier to implement instead of typing it every single time? This is the intended layout.
I've included my activityMain.xml and styles.xml files below.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="24dp"
tools:context="com.example.android.musiclibrary.MainActivity"
android:background="#fcfcfc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
style="#style/song_group">
<ImageView
android:src="#drawable/n30_Seconds_to_Mars"
android:id="#+id/thumbnail1"
style="#style/icon"
/>
<TextView
android:layout_toRightOf="#id/thumbnail1"
android:text="Up In The Air"
android:id="#+id/song1"
style="#style/song"
/>
<TextView
android:layout_toRightOf="#id/thumbnail1"
android:text="30 seconds to Mars"
style="#style/artist"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
Here's my styles.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="icon">
<item name="android:scaleType">fitCenter</item>
<item name="android:maxWidth">42dp</item>
<item name="android:maxHeight">42dp</item>
<item name = "android:adjustViewBounds">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="song">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">6dp</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">17sp</item>
</style>
<style name="artist">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_marginLeft">6dp</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">#000000</item>
<item name="android:textStyle">italic</item>
</style>
<style name="song_group">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:padding">10dp</item>
</style>
</resources>

Change action menu text color and reduce spacing toolbar android?

I am using the toolbar with navigation view for side menu
I also have 2 action menu items of which one denotes a numeric value and other is an image.
I need to reduce the spacing between those 2 menuitems and also change the color of the item text.
This is my activity XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:titleTextAppearance="#style/AppTheme.Toolbar.Title">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
This is theme file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<!-- Customize color of navigation drawer icon and back arrow -->
<item name="colorControlNormal">#android:color/black</item>
<item name="android:actionButtonStyle">#style/ActionButtonStyle</item>
<item name="android:actionMenuTextColor">#android:color/black</item>
</style>
<style name="AppTheme.Toolbar.Title" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<!-- Set proper title size -->
<item name="android:textSize">#dimen/abc_text_size_title_material_toolbar</item>
<!-- Set title color -->
<item name="android:textColor">#android:color/black</item>
</style>
<style name="ActionButtonStyle" parent="#android:style/Widget.Holo.Light.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
This is the menu file
<?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/lollyMenu"
android:icon="#drawable/jar"
android:orderInCategory="101"
android:title=""
app:showAsAction="always" />
<item
android:id="#+id/Amt"
android:orderInCategory="100"
android:title="0"
app:showAsAction="always" />
</menu>
You can try negative margin and textColor:
<?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/lollyMenu"
android:icon="#drawable/jar"
android:orderInCategory="101"
android:title=""
app:showAsAction="always" />
<item
android:id="#+id/Amt"
android:orderInCategory="100"
android:title="0"
android:textColor="#fff"
app:showAsAction="always"
android:layout_marginRight="-10dp" />
</menu>

Change the text color of the popup menu

I am using Theme.AppCompat.Light.NoActionBar theme. I am getting a white background for popup menu and also the color of menu item is white that makes it invisible. I tried many solutions with no success.
This is my styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionMenuTextColor">#000000</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
<!-- Customize your theme here. -->
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small" tools:ignore="NewApi">
<item name="android:textColor">#000000</item>
<item name="android:textSize">15sp</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large" tools:ignore="NewApi">
<item name="android:textColor">#000000</item>
<item name="android:textSize">25sp</item>
</style>
This is the toolbar
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/toolbar"
android:elevation="8dp"
app:theme="#style/AppTheme"
app:title="Troll Cricket" />
Add these lines to your Toolbar.xml file.
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
This will allow you to have a dark toolbar and light-themed overflow menu.

Categories

Resources