问题
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?
回答1:
Use this
protected void showBackButton() {
mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerToggle.setDrawerIndicatorEnabled(false);
final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.ic_back); (R.drawable.ic_back==> your own drawable .png)
mDrawerToggle.setHomeAsUpIndicator(upArrow);
setSupportActionBar(mToolbar);
}
回答2:
Try this:
<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.Dark.ActionBar"/>
I.e. using @style/ThemeOverlay.AppCompat.Dark.ActionBar
(instead of @style/ThemeOverlay.AppCompat.Dark
) when setting the toolbar's app:theme
.
来源:https://stackoverflow.com/questions/36420991/android-custom-toolbar-how-to-set-back-button-be-white