I have an application with a Toolbar and I want to make the Toolbar transparent.
I have searched and got some answers but they are not working at all!
now I sign up and asking question , how should i make my Toolbar transparent? (I mean no background at all).
my API is 15, android 4.0.3
<?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="wrap_content"
android:minHeight="?attr/actionBarSize"
local:theme="#style/ThemeOverlay.AppCompat"
local:popupTheme="#style/ThemeOverlay.AppCompat" />
When you declare the Toolbar in your Java Activity, try using this code to set the Opacity/Alpha value like so:
toolbar.getBackground().setAlpha(0);
Also you could use this theme to set the background to empty
<style name="Theme.Custom" parent="#android:style/Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="CustomActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
Then in your Toolbar, set the theme with this value
app:theme="#style/CustomActionBar"/>
set toolbar hidden: yes maybe it can work.
Related
I have an app that uses a custom Toolbar style. Previously, it applied the theme correctly, but after a recent update of Android Studio, it has stopped working correctly.
The theme.xml is defined like so:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="OurTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:listSeparatorTextViewStyle">#style/BlueListSeparatorTextViewStyle</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/action_bar_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<!--<item name="colorPrimaryDark">#color/my_awesome_darker_color</item>-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/btn_accent_color</item>
</style>
<!-- Application theme. -->
<style name="OurTheme" parent="OurTheme.Base">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:listSeparatorTextViewStyle">#style/BlueListSeparatorTextViewStyle</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
</resources>
Our styles.xml contains:
<!-- ActionBar styles ThemeOverlay.AppCompat.ActionBar -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
actionbar_text is defined in our colors.xml:
<color name="actionbar_text">#ffffffff</color>
Finally, our custom toolbar layout:
<?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="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark" />
Previously, this worked and our app had white text in its custom toolbar. It now defaults to black everywhere in the app and the only method I have found that can change the color of the toolbar title text (other than doing it in code) is to change the toolbar layout to this:
<?xml version="1.0" encoding="utf-8"?>
<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="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:titleTextAppearance="#style/MyActionBarTitleText"
app:theme="#style/ThemeOverlay.AppCompat.Dark" />
Note that now I am specifically telling the actionbar to use MyActionBarTitleText style.
I have also tried to specifically tell it to use the custom theme here as well, by changing the "app:theme" to:
app:theme="#style/MyActionBar"
but this hasn't helped.
I'm afraid I'm at a loss. I know the base theme works as I can change the background colour, but using the actionBarStyle item simply refuses to work.
This has also affected text layouts and justifications to some of our custom button layouts as well and I can't figure out why it has stopped working. Does anyone have any suggestions?
It's very late but answering it.
Create a custom theme for your toolbar and set android:background
<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/blue</item> // change your color here and add other attributes
</style>
Now apply this theme to your toolbar in XML like:
style="#style/ToolbarStyle"
I have a toolbar with the following layout
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/primary_dark"
android:theme="#style/ToolbarTheme"/>
and the theme I'm using
<style name="ToolbarTheme" parent="AppTheme">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:popupBackground">#color/white</item>
<item name="android:textColor">#color/black</item>
<item name="actionMenuTextColor">#color/black</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
Now on pre-lollipop devices the selectable background for the menu items works just fine but on lollipop there's no background for tapping those items. What do I need to add to get the ripple effect for lollipop?
OK so for anyone interested I figured it out. You need to define a separate style for your toolbar in the 'values-v21' folder then add the following items to it:
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">#color/ripple_material_dark</item>
By the way, my AppTheme inherits from Theme.AppCompat.Light.NoActionBar
I am using Toolbar for the purpose of material design in my application. Everything working fine but except when it comes to change the menu item text color I am completely stuck up with the solution. I am also posting screenshot of the text that should be taken and code I am using in my application for your reference. I tried several alternate methods like assigning as follows
<item name="android:actionMenuTextColor">#color/white</item>
<item name="android:textColor">#000</item>
But known of the above solutions works for me.
Requirement screenshot:
Need to change SKIP menu item from black to white color.
styles.xml
<style name="ToolBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/blue</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:actionMenuTextColor">#color/white</item>
<item name="android:textColor">#000</item>
</style>
toolbar.xml
<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="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true"
android:background="?attr/colorPrimary"/>
manifests
<activity
android:name=".activity.HomeActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|screenLayout|orientation"
android:theme="#style/ToolBarTheme"></activity>
I really dont know where I am committing mistake. Please help me. Thanks in advance
Change this
<item name="android:actionMenuTextColor">#color/white</item>
to
<item name="actionMenuTextColor">#color/white</item>
And apply the theme to the toolbar:
android:theme="#style/ToolBarTheme"
You style your widgets and provide themes for your activity.
I want to set background of toolbar transparent.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:elevation="4dp"
android:id="#+id/tool_bar_org"
android:paddingTop="0dp">
</android.support.v7.widget.Toolbar>
Here is my toolbar layout background is not being transparent
just show in white color
toolbar = (Toolbar) findViewById(R.id.tool_bar_org);
toolbar.getbackgroud().setAlpha(0);
setSupportActionBar(toolbar);
Its not working. Can you please tell me how to make it transparent.
This is the theme I have used in my project to make the appCompact ActionBar as transparent, modify it according to your needs:
<style name="adhoctheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/adhocblack</item>
<item name="actionBarStyle">#style/adhocblack</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="adhocblack" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#0D000000</item>
<item name="background">#color/appcompact_transparent_actionbar_bg</item>
<item name="android:icon">#drawable/logo_header_2</item>
</style>
Where appcompact_transparent_actionbar_bg = #0D000000
Important:
Have a look here to check how different values folders contain specific style files to render on various API's
I'm trying to center the Toolbar text title and I can't. I've already tried to use a theme (didn't work) and Java code (as I'm working with API level 13 I can't use .setTextAligment), I've also tried getSupportActionBar().setDisplayOptions(toolbar.TEXT_ALIGNMENT_CENTER) that didn't work too.
Can you please help me?
styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="AppTheme.Toolbar.Title" parent="Theme.AppCompat.NoActionBar">
<!-- Set proper title size -->
<item name="android:textSize">#dimen/abc_text_size_title_material_toolbar</item>
<item name="android:gravity">center</item>
<item name="android:layout_gravity">center</item>
</style>
</resources>
layout.xml
<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="70dp"
android:background="#drawable/toolbar_main"
style="#style/AppTheme.Toolbar.Title">
</android.support.v7.widget.Toolbar>
I've already tried the solution described here, but it didn't worked for me.