뒤로 버튼의 색상을 변경할 수 없습니다. 툴바 머티리얼 디자인을 사용하고 있습니다. 내 앱에서는 도구 모음의 검정색 배경을 적용하고 있지만 뒷면 디자인은 기본적으로 검정색이므로이 뒤로 버튼의 색상을 변경하고 싶습니다. 저에게 해결책을주십시오.
감사합니다
뒤로 버튼의 색상을 변경할 수 없습니다. 툴바 머티리얼 디자인을 사용하고 있습니다. 내 앱에서는 도구 모음의 검정색 배경을 적용하고 있지만 뒷면 디자인은 기본적으로 검정색이므로이 뒤로 버튼의 색상을 변경하고 싶습니다. 저에게 해결책을주십시오.
감사합니다
답변:
이 스타일 사용
<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">@drawable/back_button_image</item>
</style>
styles.xml에 스타일을 추가 할 수 있습니다.
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- Customize color of navigation drawer icon and back arrow -->
<item name="colorControlNormal">@color/toolbar_color_control_normal</item>
</style>
app : theme를 사용하여 툴바 layout.xml의 툴바에 테마로 추가하고 아래를 확인하십시오.
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ToolbarTheme" >
</android.support.v7.widget.Toolbar>
다음은 app:themeToolbar에 Light and Dark 테마를 구현하는 가장 간단한 방법 입니다. Toolbar 태그 의 값을 변경해야합니다.
app : theme = "@ style / ThemeOverlay.AppCompat.Light"
app : theme = "@ style / ThemeOverlay.AppCompat"
Theme.AppCompat.Light.DarkActionBar나의 경우에는.
흰색 도구 모음 제목 및 흰색 위쪽 화살표의 경우 다음 테마를 사용하십시오.
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
이것을 사용하십시오 :
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">@color/white</item>
</style>
이 시도,
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
흰색 뒤로 단추 (←)와 흰색 도구 모음 제목을 원하면 다음을 따르십시오.
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
검은 색 뒤로 버튼 (←)과 검은 색 도구 모음 제목을 원하는 경우 테마를에서 Dark로 변경 Light합니다.
app:navigationIcon및 제목 색상을 사용하여 자신의 아이콘을 사용할 수 있습니다.app:titleTextColor
예:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary"
app:navigationIcon="@drawable/ic_arrow_back_white_24dp"
app:titleTextColor="@color/white" />
app:navigationIcon="@drawable/ic_back_black"
테마가 생성되어야하는데 문제가 있다고 생각하지만 동적으로 설정된 검은 색 화살표가 있습니다.
Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
backArrow.setColorFilter(getResources().getColor(R.color.md_grey_900), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
를 사용하고 MaterialToolbar기본 색상을 재정의하십시오.
<com.google.android.material.appbar.MaterialToolbar
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:theme="@style/MyThemeOverlay_Toolbar"
..>
와:
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<!-- color used by navigation icon and overflow icon -->
<item name="colorOnPrimary">@color/...</item>
</style>
당신이 사용하는 경우 androidx.appcompat.widget.Toolbar또는를 MaterialToolbar 기본 스타일에 ( Widget.MaterialComponents.Toolbar)를 사용할 수 있습니다 :
<androidx.appcompat.widget.Toolbar
android:theme="@style/MyThemeOverlay_Toolbar2"
와:
<style name="MyThemeOverlay_Toolbar2" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<!-- This attributes is used by title -->
<item name="android:textColorPrimary">@color/white</item>
<!-- This attributes is used by navigation icon and overflow icon -->
<item name="colorOnPrimary">@color/secondaryColor</item>
</style>
내가 사용하고 <style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar>내 안드로이드 응용 프로그램에서 테마 및 NoActionBar 테마로, colorControlNormal건물 내 도구 모음에서 탐색 아이콘 기본 뒤로 단추 화살표의 색상을 변경하는 데 사용됩니다
styles.xml
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">@color/your_color</item>
</style>
간단하고 걱정 없음
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextColor="@color/white"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/testing" />
</android.support.design.widget.CoordinatorLayout>
Material Components 라이브러리를 사용하여 이렇게했습니다.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="drawerArrowStyle">@style/AppTheme.DrawerArrowToggle</item>
</style>
<style name="AppTheme.DrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@android:color/white</item>
</style>
Android 21 이상에서 툴바의 스타일을 지정하는 것은 약간 다릅니다.
<style name="DarkTheme.v21" parent="DarkTheme.v19">
<!-- toolbar background color -->
<item name="android:navigationBarColor">@color/color_primary_blue_dark</item>
<!-- toolbar back button color -->
<item name="toolbarNavigationButtonStyle">@style/Toolbar.Button.Navigation.Tinted</item>
</style>
<style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
<item name="tint">@color/color_white</item>
</style>
시스템 배경색 을 흰색으로 원하면 이 코드를 사용할 수 있습니다.
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_notification"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<include layout="@layout/action_bar_notification" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
참고 :- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 열쇠
붙여 넣기는 작업 표시 줄에 뒤로 버튼을 표시하려는 활동에 있습니다.
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_notification);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);