Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change style of AppBarLayout in the entire theme?

I want to do something very simple: Change the background for the AppBarLayout component for the entire theme.

So here's my theme, where I don't know which attribute to overwrite:

<style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Some color attributes that doesn't actually matter... -->

</style>

And here's the new theme for AppBarLayout that I want to apply to the above theme:

<style name="DefaultAppBarLayout" parent="Widget.Design.AppBarLayout">
    <item name="android:background">@android:color/transparent</item>
</style>

Should I be inheriting styles from another parent for the BaseTheme? Or which <item name="attribute_name"></item>should I apply my new style to?

EDIT 1

Current behavior

<com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/more_actionbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:title="@string/moremenu_fragment_title"/>
    </com.google.android.material.appbar.AppBarLayout>

This is the code that I want to write; without specifying every single time "background color = white"

Desired behavior

Code that works for it; but I don't want to write android:background="@color/colorTrueWhite" for every AppBarLayout in my XMLs

<com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorTrueWhite">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/more_actionbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:title="@string/moremenu_fragment_title"/>
    </com.google.android.material.appbar.AppBarLayout>
like image 686
Some random IT boy Avatar asked Nov 07 '22 19:11

Some random IT boy


1 Answers

In some higher version than 1.0.0 of the google material implementation for android dependecy they added the appBarLayoutStyle. I was using that version when I asked this question. I guess now it's kind of pointless but yeah... the solution is to upgrade to a newer version of the material design library and use the customizable attribute in your <style name="AppTheme">

like image 75
Some random IT boy Avatar answered Nov 14 '22 07:11

Some random IT boy