cs x cs x - 2 months ago 8
Android Question

android custom toolbar how to set back button be white?

style/AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorBackground</item>
</style>


style/ActivityCustomToolbarTheme:

<style name="ActivityCustomToolbarTheme" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>


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:theme="@style/ThemeOverlay.AppCompat.Light"/>


i set the
app:theme
to this,but it always is black.if set
@style/ThemeOverlay.AppCompat.Dark
,it is grey.

other activity that don't custom is ok,but how to set the custom theme?

Ram Ram
Answer

Use this

@SuppressLint("NewApi")
protected void changeBackArrowColor() {
    final Drawable upArrow;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            upArrow = getResources().getDrawable(
                    R.drawable.abc_ic_ab_back_mtrl_am_alpha, null);
        } else {
            upArrow = getResources().getDrawable(
                    R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        }
        upArrow.setColorFilter(getResources().getColor(R.color.white),
                PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(upArrow);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }