I have looked around many times already at different posts and none of them have solved this problem for me. My XML defined menu item always show up in the the overflow, and it show up twice. Here is the XML file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/add_Playlist"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="ifRoom|withText"
android:title="#string/addPlaylist" />
</menu>
I'm inflating the menu on top of my toolbar in the activity file:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setActionBar((android.widget.Toolbar) findViewById(R.id.toolbar));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
And yet the menu items show up in the overflow. In Android Studio's render view the menu looks correct.
If you want me to attach a snapshot I will. I'm running the app on an emulator with API 23 (For now). I don't know if I should include any other files but tell me if you want them. Thanks in advance!
[EDIT] Here is a screenshot of the toolbar:
https://gyazo.com/2743b74a8aee07035b8398f1b41002c4
Here is my styles.xml:
<resources
xmlns="http://schemas.android.com/apk/res-auto">
<color name="card_title_text">#111111</color>
<color name="card_desc_text">#aaaaaa</color>
<color name="action_bar_text">#ffffff</color>
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.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/action_bar_text</item>
<item name="android:navigationBarColor">#color/black</item>
<item name="android:colorForeground">#color/foreground_material_light</item>
<item name="android:colorBackground">#color/background_material_light</item>
<item name="android:statusBarColor">#color/statusBarColor</item>
<item name="android:windowBackground">#color/windowBackground</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="actionMenuTextColor">#color/action_bar_text</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
I also tried setting app:showAsAction="always" but it didn't work. No visible change.
I'm not sure I understand fully - do you mean you want to see the icons in the toolbar instead of the words in your #string/addPlaylist
If so, you need to change the following line in your menu item:
app:showAsAction="always"
Related
I am making a notes app.In that app i want an actionmode to trigger when long pressed on any item.It works but i cant change any style attributes of the actionmode.I have included my custom style in the styles.xml of my app, still doesn't work
styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/white</item>
<item name="android:textColor">#color/black</item>
<item name="colorPrimaryVariant">#color/blue_main</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/white</item>
<item name="colorSecondaryVariant">#color/white</item>
<item name="colorOnSecondary">#778899</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="m">#D3D3D3</item>
<item name="android:actionBarStyle" >#style/Theme.AppCompat.Light</item>
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="actionBarTheme">#style/Theme.AppCompat.Light</item>
</style>
<style name="Widget.ActionMode" parent="#style/Widget.AppCompat.Light.ActionMode.Inverse">
<item name="background">?attr/actionModeBackground</item>
<item name="android:actionBarDivider">#null</item>
<item name="actionModeCloseDrawable">#drawable/cancel</item>
<item name="android:actionModeBackground">#android:color/white</item>
</style>
<style name="CustomMaterialDialog" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<!-- Background Color-->
<item name="android:background">#FFFFFF</item>
<!-- Text Color for title and message -->
<item name="colorOnSurface">#BF40BF</item>
<!-- Text Color for buttons -->
<item name="colorPrimary">#BF40BF</item>
<item name="shapeAppearanceOverlay">#style/ShapeAppearance.MaterialComponents.LargeComponent
</item>
</style>
</resources>
I specifically want to remove a green divider line that shows up at the bottom of the contextual menu i have attached the picture please see green divider line below the action mode menu
solved it. The problem was with the theme applied to the custom toolbar that i implemented. applied the lighttheme and everything works fine
So I know there are a ton of these questions, but every time I try what they say, my app does not seem to remove the title bar. I have done the style change:
<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:windowNoTitle">true</item> <!-- This should work but it does not -->
</style>
I have also tried:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //This guy here
setContentView(R.layout.activity_title);
The above works but I still want to use the space the title bar takes for content in my app, which is why I want to be able to modify the XML code rather than use java. Any suggestions?
You can either:
<style name="noActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and in your layout(at the root layout)
android:theme="#theme/noActionBar"
Or
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
However, the last one also hides the Statusbar. You can also set the theme to a default theme(look through the themes and find those with NoActionBar). The last one is useful if you have no plans to style the activity(for an instance if you use SurfaceView) with custom colors, etc.
For an instance you can change AppBaseTheme to have the parent Holo.Light.NoActionBar or any similar theme, but the name has to contain NoActionBar, othervise it has an actionbar
Add the below theme to style.xml:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then set this theme to your Activity in manifest:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
I am using a theme in styles.xml as below:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/md_blue_700</item>
<item name="android:colorAccent">#color/md_blue_900</item>
<item name="android:colorPrimaryDark">#color/md_blue_900</item>
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="android:colorControlNormal">#color/md_blue_700</item>
<item name="android:colorControlActivated">#color/md_blue_700</item>
<item name="android:colorControlHighlight">#color/md_blue_700</item>
<item name="android:textColorPrimary">#color/md_white_1000</item>
</style>
which I am declaring as android:theme in AndroidManifest.xml:
<activity
android:name=".LoginActivity"
android:theme="#style/AppTheme"
android:label="#string/activity_login_actionbar" />
The problem is highlighted in red in the image below.
Since I am setting
<item name="android:textColorPrimary">#color/md_white_1000</item>
to white the text in the progress bar also appears white and is invisible. If I change it to gray, the text in the action bar also changes to gray which I do not want.
I have tried things such as creating a seperate theme for the progress dialog but when I do that I lose the rounded corners of the dialog box and such.
This is my java code for creating the spinner:
progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle("Attempting Sign In");
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
How should I go about solving this problem?
All answers appreciated!
You can use Theme.AppCompat.Light.DarkActionBar and remove <item name="android:textColorPrimary">#color/md_white_1000</item> in your theme style, then the title will become white. You can check the comparison between Light and Dark themes here
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/md_blue_700</item>
<item name="android:colorAccent">#color/md_blue_900</item>
<item name="android:colorPrimaryDark">#color/md_blue_900</item>
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="android:colorControlNormal">#color/md_blue_700</item>
<item name="android:colorControlActivated">#color/md_blue_700</item>
<item name="android:colorControlHighlight">#color/md_blue_700</item>
</style>
I have a custom theme that I displayed for my application. However, in my main activity class I set a custom font for the action bar font.
// Make sure you find out why it appears after a whole 1 second after the app appears
SpannableString s = new SpannableString("GetDisciplined");
s.setSpan(new TypefaceSpan(this, "roboto-light.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
ActionBar actionBar = getActionBar();
actionBar.setTitle(s);
// set the action bar in this activity as the home
actionBar.setHomeButtonEnabled(true);
Upon launching the app, I want to immediately show the custom font.
I did some research and most solutions didn't work, but I am trying to now use launch a "splash screen" application theme without an action bar and then set the custom_theme with an action in my main activity class.
Kind of like this.
https://stackoverflow.com/a/12724687/3120659
But I am unsure how to do that modify my current style theme to do that.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Light_appalled" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_light_appalled</item>
<item name="popupMenuStyle">#style/PopupMenu.Light_appalled</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Light_appalled</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Light_appalled</item>
<item name="actionDropDownStyle">#style/DropDownNav.Light_appalled</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Light_appalled</item>
<item name="actionModeBackground">#drawable/cab_background_top_light_appalled</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_light_appalled</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Light_appalled</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.Light_appalled.Widget</item>
</style>
<style name="ActionBar.Solid.Light_appalled" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_light_appalled</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_light_appalled</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_light_appalled</item>
<item name="progressBarStyle">#style/ProgressBar.Light_appalled</item>
</style>
<style name="ActionBar.Transparent.Light_appalled" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/ab_transparent_light_appalled</item>
<item name="progressBarStyle">#style/ProgressBar.Light_appalled</item>
</style>
<style name="PopupMenu.Light_appalled" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_light_appalled</item>
</style>
<style name="DropDownListView.Light_appalled" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_light_appalled</item>
</style>
<style name="ActionBarTabStyle.Light_appalled" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_light_appalled</item>
</style>
<style name="DropDownNav.Light_appalled" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_light_appalled</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_light_appalled</item>
<item name="android:dropDownSelector">#drawable/selectable_background_light_appalled</item>
</style>
<style name="ProgressBar.Light_appalled" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_light_appalled</item>
</style>
<style name="ActionButton.CloseMode.Light_appalled" parent="#style/Widget.AppCompat.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_light_appalled</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Light_appalled.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Light_appalled</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Light_appalled</item>
</style>
</resources>
Unfortunately
<item name="android:windowNoTitle">true</item>
did not work, so I am trying to figure out how to do it.
I put an ActionBar into my app and changed the background color, as I'll show below. Oddly enough, the color behind the text on the ActionBar won't change. (picture)
I looked around and found this:
<item name="android:actionBarItemBackground">#null</item>
But I would prefer not to use it because then my minSdk has to be set to 14, whereas I have it at 11 now. I did try boosting it up to 14 to see if this tag would work, but I again couldn't get the color to change.
Does anyone have any experience with this? Many thanks in advance for your help.
Styles.xml:
<style name="AppBaseTheme" parent="Theme.AppCompat">
</style>
<!-- Application theme. -->
<style name="MyAppTheme" parent="AppBaseTheme">
<item name="android:colorBackground">#color/background</item>
<item name="android:background">#color/background</item>
<item name="android:textColor">#color/myWhite</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="actionMenuTextColor">#color/myWhite</item>
<!--Support Library compatibility-->
<item name="background">#color/myBlack</item>
</style>
drawable/actionbar_background:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/myBlack" />
</shape>
menu/login.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
<item android:id="#+id/action_settings"
android:title="#string/settings_label"
android:showAsAction="never" />
</menu>
And finally, inside the LoginActivity class, the onCreateOptionsMenu method:
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return super.onCreateOptionsMenu(menu);
}
Thanks again!
I figured it out. Turns out I was using the wrong attribute -- instead of using android:background in the styles.xml file, you need to use android:windowBackground. android:background changes all sorts of other things, too.