How to apply a theme/styling to ActionMenuView? - android

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!

Related

How to change default Toolbar title text from #string/app_name to "", but only changing styles.xml?

I have an app with
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
In some activities I add the ToolBar in xml manually that contains #string/app_name title text by default.
I know that I can call setDisplayShowTitleEnabled(false) or something like that, but it does not suit me.
I need to other way like changing something in AppTheme so the title text will be changed through all app by default.
How to do that?
Toolbar that I added:
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#color/colorAccent"
app:navigationIcon="#drawable/ic_default_nav_icon_white" />
You can try creating a new layout file and adding the Toolbar code in that.
See below this is the layout_app_bar.xml
Where you can specify the title of toolbar.
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.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="50dp"
android:background="#color/colorPrimary"
android:elevation="4dp"
app:title="WhateverName"
app:titleTextAppearance="#style/AppbarTitle"
app:titleTextColor="#color/colorWhite" />
Then in you activities you can include the layout file just like any other tag. you can use this single layout file of toolbar in all activities.
<LinearLayout>
<include
android:id="#+id/appbar"
layout="#layout/layout_app_bar" />
</LinearLayout>
I Hope it helped you.
Happy Coding!!!

Show app icon in the middle of the appbar

Right now, as an example, the app looks like this:
How do I programatically or using xml make the appbar look like this:
I've tried setting the appbar icon as if it were a background, but it looks rather odd.
You can add the application icon as a menu item to appbar with android:show="always".
Another workaround is to place an imageView in your toolbar, which is inside the appBar. You can then change the position of this imageview through xml code or programmatically.
<android.support.design.widget.AppBarLayout
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="?actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ToolbarColoredBackArrow"
app:popupTheme="#style/AppTheme.PopupOverlay" >
<ImageView
android:id="#+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_small"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

Android - Change Action Bar Text Color

In my app I've got a theme without an action bar, but for one of my activities I need an action bar with white title. So, here is it's code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="#color/color_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="Title"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<fragment android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
As you see, this activity also contains Google Maps Fragment.
Result:
As you see, title color is not white. Why? I wonder.
After #Raghunandan: Just add this string to you AppBaseTheme in styles.xml:
<item name="android:textColorPrimary">#android:color/white</item>
Try this
toolbar.setTitleTextColor(Color.WHITE);
Hope this helps
if(Build.VERSION.SDK_INT>=11){
android.app.ActionBar ab=getActionBar();
ab.setBackgroundDrawable(new ColorDrawable(0xff3b3f54));//3b3f54 is html color code for purple, you can put any desired color code like ffffff for white
ab.setDisplayHomeAsUpEnabled(true);
}

Change android toolbar background color alone

<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.

Android design library TabLayout background issues

When I setup the tabBackground attribute of the "22.2.0 Android design library" TabLayout (android.support.design.widget.TabLayout) two problems appear :
The ripple effect in the tabs is lost
The tab indicator disappears.
This occurs on both Lollipop and Kitkat devices.
Without the tabBackground settings, both ripple effect and tab indicator work but the background has a default color that is different from the toobar, which is not exactly conform to the material design guidelines.
Please find below the XML :
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabBackground = "?attr/colorPrimary" />
Use android:background="?attr/colorPrimary" instead of app:tabBackground = "?attr/colorPrimary".
If you have a dark primary color, you may also want to change the theme to ThemeOverlay.AppCompat.Dark. This makes the text and the ripple color white.
Full example:
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark" />

Categories

Resources