Make toolbar and menu button have smaller height - android

I have a toolbar (please see xml below). Is there any easy way to make the tool bar thinner and keep the menu button.
Or maybe just have a menu button in some corner?
This started out as a full screen activity, but i roll up my own view and do a: setContentView(view);
thanks
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<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="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
</resources>

Specifying this styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionBarSize">20dp</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="displayOptions">homeAsUp</item>
</style>
<style name="MyActionButtonStyle" parent="Widget.AppCompat.Light.ActionButton">
<item name="android:minWidth">20dp</item>
<item name="android:minHeight">20dp</item>
</style>
Will result in this output:

Related

android:theme parameter inside manifest ignored

I have AppTheme style in my styles.xml file. In manifest file i choose it like application theme.
I want to login activity unique style and I created login style, and set it in manifest. But it is not working, LoginActivity still takes AppTheme.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:name=".application.TrainerApp"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".activities.login.LoginActivity"
android:theme="#style/LoginTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In style.xml
<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>
</style>
<style name="LoginTheme" parent="#style/AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Try like this :-
<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>
</style>
<style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#ff0</item>
<item name="colorPrimaryDark">#0ff</item>
<item name="colorAccent">#f0f</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Instead of :-
<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>
</style>
<style name="LoginTheme" parent="#style/AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Remove android:theme="#style/AppTheme" from your application tag and apply theme for each activity separately. For more detail, please see my link: http://androidkeeda.com/android-working-on-material-theme

Change AppTheme dynamically

Goal: I want to allow user to change the color theme of my app.
Themes (styles.xml):
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="android:statusBarColor">#color/indigoColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.SearchActivity">
<item name="android:statusBarColor">#android:color/darker_gray</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
<!-- Colors -->
<style name="AppTheme.Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="android:statusBarColor">#color/indigoColorPrimaryDark</item>
</style>
<style name="AppTheme.Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
<item name="android:statusBarColor">#color/blueColorPrimaryDark</item>
</style>
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
</style>
<!-- some other colors -->
</resources>
As you can see, I have the main theme AppTheme that as a default color ("indigo").
I have three other themes FullScreen, MainActivity and SearchActivity that derive from AppTheme, and then colors themes.
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.superbstudios.reportnote">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SignInActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.FullScreen" />
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
android:label=""
android:theme="#style/AppTheme.SearchActivity"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/AppTheme" />
<activity
android:name=".GuideActivity"
android:label="#string/title_activity_guide"
android:theme="#style/AppTheme" />
</application>
</manifest>
Now, only SignInActiviy, MainActivity and SearchActivity has their own themes, the other activity (also application) has AppTheme.
What I do: I create a BaseActivity class, and all activity extend this class.In BaseActivity in onCreate method before super declaration I use this code to change color theme:
setTheme(R.style.AppTheme_Red);
Problem: This code change the theme for all activity and also for SignInActiviy, MainActivity and SearchActivity that needs a different theme.
I don't know if the colors theme are useful.
The only things i want is to change the AppTheme colors like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
So, what I have to do to change colors of my app?
I solved it by changing styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.SearchActivity">
<item name="android:statusBarColor">#android:color/darker_gray</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
<!-- Colors -->
<style name="Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
</style>
<style name="Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
</style>
<style name="Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
</style>
</resources>
And in my BaseActivity i use this code:
getTheme().applyStyle(R.style.Blue, true);
Referenced to the comment
I'll answer by taking Red color as an example
If you only want to change the colorPrimary then keep only it.
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
</style>
Other wise create two themes for Red color. One with status bar color and other inheriting that with transparent status bar.
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
</style>
<style name="AppTheme.RedTransparentStatus" parent="AppTheme.Red>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
So if you want status bar to transparent you can set the second theme or else the first.
From my understanding, you want to keep the default "Indigo" color for
SignInActivity, MainActivity, SearchActivity.
Todo so inherit the relevant themes of those activities with AppTheme
<style name="AppTheme.SearchActivity" parent="AppTheme">
...
</style>

Can't apply Theme from Android Action Bar Style Generator

I finished Android Action Bar Style Generator and downloaded the zip from there.
I copied and pasted all the folder in res, then changed the theme to let my app use the theme I edited. but The result is nothing changed!!!!
I am still beginner here. I am still not sure if there are other thing to deal with about changing Theme.
style_example.xml in folder values (created by the generator)
<style name="Theme.Example" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_example</item>
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Example</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="actionDropDownStyle">#style/DropDownNav.Example</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="actionModeBackground">#drawable/cab_background_top_example</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_example</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Example</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.Example.Widget</item>
</style>
<style name="ActionBar.Solid.Example" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_example</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_example</item>
<item name="progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="ActionBar.Transparent.Example" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/ab_transparent_example</item>
<item name="progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="PopupMenu.Example" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>
<style name="DropDownListView.Example" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_example</item>
</style>
<style name="ActionBarTabStyle.Example" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example</item>
</style>
<style name="DropDownNav.Example" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_example</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
<item name="android:dropDownSelector">#drawable/selectable_background_example</item>
</style>
<style name="ProgressBar.Example" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_example</item>
</style>
<style name="ActionButton.CloseMode.Example" parent="#style/Widget.AppCompat.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_example</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Example.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Example</item>
</style>
AndroidManifest.xml (I just forgot to change the name so it is "Theme.Example")
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mes.learnupdater1" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Example" > --------------------- Theme applied
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="#string/title_activity_main2" >
</activity>
</application>
</manifest>
If you want customized your them you need to edit theme under the value folder style. XML file

Change in actionbar on opening in Android

I have changed actionbar color and other things to open in required color and text but when I open the app: The app opens with default theme and immediately changes to given theme.
This happens in phones like Galaxy Nexus, Nexus 4 but not on Nexus 5. I am not sure why this is happening?
I have set the actionbar before setContentView in my APP
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setIcon(android.R.color.transparent);
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarColor)));
setContentView(R.layout.activity_main);
}
I got the theme using: http://jgilfelt.github.io/android-actionbarstylegenerator/
My style which I got from the above looks like this:
<style name="Theme.link" parent="#android:style/Theme.Holo">
<item name="android:actionOverflowButtonStyle">#style/ThemeFor.OverFlow</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_link</item>
<item name="android:popupMenuStyle">#style/PopupMenu.link</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.link</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.link</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.link</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.link</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_link</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_link</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.link</item>
</style>
<style name="ActionBar.Solid.link" parent="#android:style/Widget.Holo.ActionBar.Solid">
<item name="android:background">#drawable/ab_background_textured</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_link</item>
<item name="android:backgroundSplit">#drawable/ab_background_textured_link</item>
<item name="android:progressBarStyle">#style/ProgressBar.link</item>
</style>
<style name="ActionBar.Transparent.link" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_transparent_link</item>
<item name="android:progressBarStyle">#style/ProgressBar.link</item>
</style>
<style name="PopupMenu.link" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_link</item>
</style>
<style name="DropDownListView.link" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_link</item>
</style>
<style name="ActionBarTabStyle.link" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_link</item>
</style>
<style name="DropDownNav.link" parent="#android:style/Widget.Holo.Spinner">
<item name="android:background">#drawable/spinner_background_ab_link</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_link</item>
<item name="android:dropDownSelector">#drawable/selectable_background_link</item>
</style>
<style name="ProgressBar.link" parent="#android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_link</item>
</style>
<style name="ActionButton.CloseMode.link" parent="#android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_link</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.link.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.link</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.link</item>
</style>
And I am calling the theme in Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.link" >
<activity
android:name=".Link_Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Link_Support"
android:label="#string/action_support"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ylg.linking.Link_Main" />
</activity>
</application>
Can somebody help me fix this?
Thanks!
Try to add <item name="android:actionBarStyle">#style/Theme.link</item> to your base Activity style in AndroidManifest.xml.
I think you should change a value for android:background in ActionBar.Solid.link to #color/actionBarColor.
This is happening because when the application run, it gets style from styles.xml so your default style would be visible to you and after that you are changing actiob bar in onCreate() so theme changes immediately. To solve this set the icon and background color of action bar using styles.xml only using below code.
Try it. Hope it works.
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
.....
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" arent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/actionBarColor</item>
<item name="android:text">""</item>
<item name="android:icon">#android:color/transparent</item>
</style>
And remove below code.
getActionBar().setIcon(android.R.color.transparent);
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarColor)));

Cannot change color of actionbar with appcompact v7 and Android Studio 1.1 Preview

I tried many styles to change color of actionbar but not worked.
This is my style:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#f01234</item>
</style>
My emulator version: Android 4.2
in SupportV7 version 21 change ActionBar color use colorPrimary property
Like this:
<style name="_AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="android:textColorPrimaryInverse">#android:color/white</item>
<!--<item name="android:actionBarStyle">#style/ActionBarStyle</item>-->
</style>
In styles.xml:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#eeeeee</item>
</style>
and in Manifest.xml:
<activity
android:name="yourPackage.MainActivity"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
i hope to help you.

Categories

Resources