Android Lollipop Toolbar Invert Colors - android

Am using Android L v21 Support library for Android L's Toolbar-ActionBar. I want the items in the toolbar to be white in color. i.e. Navigation Back button, Action Buttons, Overflow Actions. If I use the dark version as the application theme(Theme.AppCompat.NoActionBar) then all the toolbar items are shown in white. But when I use the light version (Theme.AppCompat.Light.NoActionBar) for the application all the toolbar items are shown dark. I want to use the light theme and want to make the toolbar to be show in white.
I have used activity.setTitleTextColor() to change the title's text color but not sure how to change the color for the rest.
SOLUTION:
Thanks to #ianhanniballake
<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_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>

Per the AppCompat v21 blog post under Styling:
Styling of Toolbar is done differently to the standard action bar, and is set directly onto the view.
With the example of:
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar" />
Note the app:theme attribute which sets the action bar to use light color text / styling (ThemeOverlay.AppCompat.Dark.ActionBar does the opposite).

Related

Mesibo - How to change toolbar color in Android

I am working with Mesibo SDK for android and I am trying to change the toolbar color without results.
I would to like to change both colors:
https://ibb.co/LrXf4d8
I tried to edit colors.xml and styles.xml but nothing is changing.
Someone has the solution?
I paste part of code.
activity_settings.xml:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/settings_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="#+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</androidx.appcompat.widget.Toolbar>
In the colors.xml file I changed colorPrimary but nothing happened.
to change the status bar (the notification bar):
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">#color/black</item>
to change the title bar:
change the value of "colorPrimary"
Use getConfig() to get the configuration instance and then use Config.mToolbarColor to set the color. You need to use ARGB color.
You can refer to the source code is here for other configurable properties
https://github.com/mesibo/ui-modules-android/blob/master/Messaging/messaging/src/main/java/com/mesibo/messaging/MesiboUI.java

how to change the color of materialToolbar in CollapsingToolbarLayout?

This is my layout
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/coll_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
If this layout isn't the first activity/fragment, the toolbar wolud have a back icon .
But the color of back icon is black.
I want it to be a whit color.
I search it in github,but nothing.
And I found the demo in google shown, they use the code android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"to the CollapsingToolbarLayout.Then the color of back icon will be the white.
I want to know what happen?
I trace back to the code android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar".I find
it's parent is Base.ThemeOverlay.AppCompat.Dark.ActionBar
Just this :<style name="ThemeOverlay.AppCompat.Dark.ActionBar" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar"/>
And then I trace back to the code Base.ThemeOverlay.AppCompat.Dark.ActionBar.I find
it haven't parent,and it implement the code
<item name="colorControlNormal">?android:attr/textColorPrimary</item>
<item name="searchViewStyle">#style/Widget.AppCompat.SearchView.ActionBar</item>
Just this :
<style name="Base.ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">?android:attr/textColorPrimary</item>
<item name="searchViewStyle">#style/Widget.AppCompat.SearchView.ActionBar</item>
</style>
So I think the key is colorControlNormal.
So I create a new style,and use it with
<item name="colorControlNormal">..my Color..</item>.But I am wrong.
So I want to know what should I make the color of back icon to be white by change one or several attribute instead of use android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" .
You are using MaterialToolbar widget from the Material Component library.
You can specify the back arrow color using app:navigationIconTint.
Here's the documentation https://material.io/components/app-bars-top/android#using-top-app-bars.

How can I simply change the color of my Toolbar DrawerToggle?

I have a toolbar defined like so:
<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:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" >
I have a navigation drawer toggle button on the toolbar enabled in code (the hamburger menu button). I want it to be white but no matter what I do, it never changes color. I saw in an open source app that they set this in the theme:
<item name="colorControlHighlight">#color/white</item>
I tried it, but still no change for me - it's always the dark almost black color.
I am using this open source app for reference since it looks like it has a white menu button: https://github.com/frogermcs/InstaMaterial
I copied it as closely as I could, but my toolbar menu button never changes color. What am I doing wrong?
Make sure that your style is a parent of Theme.AppCompat.Light.DarkActionBar
also, if you have problems with the popup menu, please add this attribute to the Toolbar view app:popupTheme="#style/ThemeOverlay.AppCompat.Light"

Android Toolbar has more padding than ActionBar, how to fix

I had to replace the actionbar to implement new UI patterns the design team wanted
The actionbar is now replaced with the ToolBar but the toolbar object is bigger than the actionbar, only marginably, but it is noticeable and not desired
Here is the XML declaration
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
How do I make it smaller? I used to be able to rely on actionBarSize which is already predefined for every screensize, I can put in a specific dp value but is that the solution for this object?
Thanks
?attr/actionBarSize is 56dp with new support lib. So even if you stick to actionbar you will get a bigger size. Set actionBarSize in your theme.

Android Material with Extended Toolbar

I'm testing material design and i'm developing an app using extended toolbar. My app is very simple: The main activity extends ActionBarActivity and my layout looks like:
<LinearLayout 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"
tools:context=".WeatherActivity"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_height="128dp"
popupTheme="#style/ActionBarPopupThemeOverlay"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/location_placeholder"
android:textAlignment="viewStart"
android:layout_gravity="start"
/>
</LinearLayout>
Now i'd like to show as title the current location. The first thing i'm noticing is in my Android Emulator (API 18) the title doesn't seem to respect material guidelines about left margin bottom margin, it appears on the left side and entered vertically inside the Toolbar. So Should i use tool bar title (toolbar.setTitle) or something else?
Second if i want to create something more complex like Title and a short description (as shown in the material guidelines in the layout structure) what should be my layout?
Thx for your support!
Ok your activity extends ActionBarActivity so you also have to make sure that the theme for this activity is a child of either Theme.AppCompat.NoActionBar or Theme.AppCompat.Light.NoActionBar. If you are not using the Theme.AppCompat variants then you can alternatively add the following lines to your theme:
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
Then all you need to do is add the Toolbar to your layout (which it looks like you already have):
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_height="128dp"
popupTheme="#style/ActionBarPopupThemeOverlay"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
Then in your activity set the Toolbar to be your ActionBar via setSupportActionBar:
Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(mToolbar);
That last part is where all the magic happens because you're saying "Android, take this Toolbar widget and use it exactly how you would use the SupportActionBar". This means that if you want to set the title/subtitle all you need to do is call:
getSupportActionBar().setTitle("Toolbar Title");
getSupportActionBar().setSubtitle("Toolbar Subtitle");
This also means that you can use the same callbacks to create a menu on the Toolbar.
To answer your questions directly:
So Should i use tool bar title (toolbar.setTitle) or something else?
You can actually use either, toolbar.setTitle() or getSupportActionBar().setTitle()
Second if i want to create something more complex like Title and a short description (as shown in the material guidelines in the layout structure) what should be my layout?
Toolbar supports Titles and Subtitles so you should be set. I would checkout the documentation just to see what all the Toolbar supports. As a general rule, if the Actionbar could do it, the Toolbar can. If you have crazy requirements beyond what is supported by the Toolbar then just remember that the Toolbar is just a fancy ViewGroup so you can add widgets/views just as easily as if it were a LinearLayout.

Categories

Resources