<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/purple"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
When I use the setTitle() method, it all works fine. But the problem is that when I change orientation (since in lollipop 5.1 I can do so) the title word is small compared to portrait version. Why such bug? and how do I solve this?
By default the Toolbar's fontsize is smaller in landscape.
If you want it to have the same size as in portrait you can set a custom titleTextAppearance:
<android.support.v7.widget.Toolbar
app:titleTextAppearance="#style/YourToolbarTitleStyle"
.../>
with YourToolbarTitleStyle being defined as a style where you specify a text size:
<style name="YourToolbarTitleStyle" parent="#style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">20sp</item>
</style>
Related
On Android I can set a transparent statusbar with the following style line:
<item name="android:windowTranslucentStatus">true</item>
I would like to display a text directly under the statusbar with the same background color of the statusbar. My problem is if I set the background color to my primaryColor it is a bit brighter because I haven't added the alpha value of the statusbar to the color.
So how can I get the alpha value of the statusbar from code to add it to my background color?
Do you want like this ?
If yes. After Android 5.0.
You should set colorPrimaryDark same as colorPrimary.
colorPrimaryDark means status bar color.
And one important step, if your layout code like this:
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
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" />
</android.support.design.widget.AppBarLayout>
Delete "AppBarLayout". Change to :
<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" />
On Activity, try get this
window.statusBarColor
I'm new to android development and I'm working on an app with ActionBar and Tabs. Recently I switched to the new support library Toolbar but the title of the toolbar (ActionBar) isn't vertically centred, while the action buttons are correctly placed.
Title image
The same problem occurs with the first MenuItem in the bar (it's moved up a little bit). Menu image
My activity extends the AppCompatActivty and the layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/action_bar_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ActionBarTheme"/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"/>
<com.myApp.app.views.widgets.ViewPager
android:id="#+id/fragmentPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
and the style:
<style name="ActionBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:textColorPrimary">#color/colorPrimaryDark</item>
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="android:background">#color/colorPrimary</item>
</style>
Could someone help me fix this issue? I've searched for a solution but found nothing.
P.S. They were correctly placed as I was using the default action bar
You should use android:theme rather than app:theme here:
android:theme="#style/ActionBarTheme"
Your style should derive from the action bar overlay:
<style name="ActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
...
</style>
Consider just using the ActionBar theme directly to start to isolate the problem.
I know this question has been asked before, and it worked for me before but after updating to App Compat revision 23, the Toolbar is now having a black text color (I want it white) and I didn't change a thing.
Toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="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"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
>
</android.support.v7.widget.Toolbar>
styles.xml
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="#attr/spinner_style">#style/spinner_style</item>
</style>
Setting toolbar to activity:
Toolbar Toolbar = (Toolbar) AppCompatActivity.findViewById(R.id.toolbar);
AppCompatActivity.setSupportActionBar(Toolbar);
ActionBar actionBar = ((AppCompatActivity)activity).getSupportActionBar();
actionBar.setTitle(title);
Change
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
to
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
The new support libraries (AppCompat) that Android Studio brings in default project templates do not insert an important attribute to style Toolbars in older Android versions.
This is what worked for me (I'm using an AppBarLayout with Toolbar and TabLayout, as shown):
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
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"
android:theme="#style/AppTheme.AppBarOverlay" <!-- Needed attribute -->
app:popupTheme="#style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:theme="#style/AppTheme.AppBarOverlay" <!-- Needed attribute -->
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
I didn't research to know exactly what happened here, but older Android versions really need the theme in every element to be styled.
Hope it helps someone who is trying to find a solution to the black text in the light toolbar theme!
I'm trying to change this toolbar color Completly White like Android Lollipop Settings action bar color but, there is a bug or something like that in our view or perhaps an Android bug!!
My toolbar:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/Theme.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
and style Arrow:
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
Result:
As you can see, the name is black! and after add these also, the search icon is a little bit black. (You can try it ;) )
But i need Completely White color with white actions.
How can achieve this?
I've tried everything you can expect!
You can try this :
taken from : https://github.com/sagar-viradiya/android-design-support-lib-demo/blob/master/app/src/main/res/layout/fragment_collapsing_toolbar.xml
Just add this in the AppBarLayout: app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
e.x:
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="256dp"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
For PopUptheme:
<android.support.v7.widget.Toolbar
android:id="#+id/Main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/Theme.AppCompat.Light" />
But i have no idea about that search action and why that is still a little bit black.
If some one knows, please guide us.
I have res/layout/toolbar.xml which is:
<?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_width="match_parent"
android:layout_height="?actionBarSize"
android:elevation="4dp"
style="#style/ToolbarStyle">
</android.support.v7.widget.Toolbar>
Here is my usage of toolbar:
<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"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
I include it in any Activity Action buttons are shown and work as expected but there is one thing that action button pressed highlight does not fit toolbar
Has anyone faced this kind of problem?
Thank you
It should be a comment, but I it is too long.
It is a material spec.
As you can see in the picture attached, the toolbar height is 64dp in tablet (56dp in smartphone), while the action button height is 48dp.
Also you can check the layout margin enabling in debug menu "show layout margin".
Source:
Here the specs for a smartphone:
If you check the style Widget.AppCompat.ActionButton you will find the minHeight and minWidth specs:
values:
<style name="Base.Widget.AppCompat.ActionButton" parent="">
<item name="android:minWidth">#dimen/abc_action_button_min_width_material</item>
<item name="android:minHeight">#dimen/abc_action_button_min_height_material</item>
</style>
<dimen name="abc_action_button_min_height_material">48dp</dimen>
<dimen name="abc_action_button_min_width_material">48dp</dimen>
values-v21:
<style name="Widget.Material.ActionButton" parent="Widget.ActionButton">
<item name="minWidth">#dimen/action_button_min_width_material</item>
<item name="minHeight">#dimen/action_button_min_height_material</item>
</style>
<dimen name="action_button_min_width_material">48dp</dimen>
<dimen name="action_button_min_height_material">48dp</dimen>
I'm not entirely sure this will solve your problem but try replacing
android:layout_height="?actionBarSize"
with
android:layout_height="?android:attr/actionBarSize"
in toolbar.xml. Again, not entirely sure it will work.