<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res`enter code here`/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar">
When i try to set toolbar alpha value as 0 at runtime it also hides the toolbar icons.
i need to set the toolbar background color as red at runtime with dynamic alpha.
please help me to fix this.
Related
I built my Toolbar like in most with minHeight set to actionBarSize:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/colorPrimary"
android:minHeight="?actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
However, if I delete this attribute, there is no difference at all. The Toolbar keeps its actionBarSize, even if I remove the menu and set the app name to an empty String, so there is nothing displayed in the Toolbar at all.
Is there anything I'm missing here?
android:minHeight="?attr/actionBarSize"
minHeight will ensure that your toolbar does not resize itself lower than ?attr/actionBarSize not matter how small the content inside the toolbar is.
EDIT
If there is nothing inside a toolbar and if minHeight is not set, the toolbar will have a default height of 56dp which is equal to ?attr/actionBarSize
So setting minHeight for toolbar is redundant
For more details, What's the height of the Android Toolbar?
This is completely intentional behaviour, The min height of ToolBar is set to action bar height by default . so yea android:minHeight="?actionBarSize" is redundunt . I couldn't find any official document on this but check out this tweet .
https://twitter.com/cyrilmottier/status/814465544279691266
On using both the attributes, android:layout_height="wrap_content" and android:minHeight="?attr/actionBarSize", there is a possibility that your toolbar height may get larger when you use larger icons.
android:minHeight ensures that your toolbar will not resize itself smaller than ?attr/actionBarSize value.
If you want your toolbar height to be fixed, just use
android:layout_height="?attr/actionBarSize"
The other attribute is not needed.
Try this one I did like this it works for me:-
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/AppTheme">
<LinearLayout
.......
/>
</android.support.v7.widget.Toolbar>
The toolbar is in Purple above the Tablayout in my XML file.
However, here as you can see for some reason the toolbar which is supposed to be the MainActivity and the Settings in those 3 dots, now for some reason the toolbar is in between the MainActivity toolbar and the tab layout.
How to fix this? I want the purple toolbar to disappear from the middle. What can I do?
To remove this toolbar the simplest way to do it is set it visibility as gone. This property will make the toolbar invisible and it doesn't take any space on the layout:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:visibility="gone"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
I'm newbie in Android so this might be the easy question for you guys but I'm stuck. I want to remove shadow of Toolbar so I followed thread how to remove shadow below actionbar with AppCompat.Light.NoActionBar? and using app:elevation="0dp" I was able to remove the shadow of Toolbar but that change the current height of Toolbar as displayed in [Image 2]. I want maintain the same exact size of Toolbar but without shadow. I also used android:fitsSystemWindows="true" from thread Android toolbar height difference but it move Profile text on top and also create white line at bottom [Image 3] .
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:minHeight="?attr/actionBarSize"/>
</android.support.design.widget.AppBarLayout>
I guess we can use android:layout_height:Xdp or android:layout_height:Xpx but is this the last option or there is default way to do this.
I want to replace the title in my Toolbar by a logo like Twitter App.
I think we can replace this programmatically like that :
mToolbar = (Toolbar) findViewById(R.id.app_toolbar);
mToolbar.setLogo(R.drawable.ic_logo);
But I want to replace it directly in my XML toolBar declaration, but I can't see the property app:logo or android:logo.
<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/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/MyCustomToolBarTheme" />
Please help me, thank you.
If you check source code of Toolbar and Toolbar's custom attributes, there are only a few attributes you can use to customize Toolbar, but logo is not one of them:
titleTextAppearance
subtitleTextAppearance
navigationIcon
...
Toolbar.setLogo(resId) seems to be the only option at the moment.
A toolbar contains a ViewGroup that you can populate with whatever views you wish --- you can add an ImageView there if you want a logo. Example:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_logo"/>
</android.support.v7.widget.Toolbar>
If you manually attach it to AppCompatActivity or ActionBar activity, it "becomes" an ActionBar, and then has to be manipulated using those code functions.
I'm using the new android.support.v7.widget.ActionMenuView (v7, r21) to mimic a split action bar in my application. My top toolbar is themed with ThemeOverlay.AppCompat.Dark.ActionBar, so its text and overflow icon appear white. The ActionMenuView content however appears black, is there a way to apply the theme there as well or at least color the option items text white?
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:support="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/bar_action"
android:background="?attr/colorPrimary"
support:popupTheme="#style/ThemeOverlay.AppCompat.Light"
support:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v7.widget.ActionMenuView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/bar_split"
android:background="?attr/colorPrimary" />
Stupid me, didn't define android:textColorPrimary in my theme!