Android에서 툴바 뒤로 버튼의 색상을 변경하는 방법은 무엇입니까?


100

뒤로 버튼의 색상을 변경할 수 없습니다. 툴바 머티리얼 디자인을 사용하고 있습니다. 내 앱에서는 도구 모음의 검정색 배경을 적용하고 있지만 뒷면 디자인은 기본적으로 검정색이므로이 뒤로 버튼의 색상을 변경하고 싶습니다. 저에게 해결책을주십시오.

감사합니다


3
<style name = "MyMaterialTheme.Base"parent = "Theme.AppCompat.Light.DarkActionBar">
Nazima Kauser MMF

답변:


79

이 스타일 사용

<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
    <item name="android:homeAsUpIndicator">@drawable/back_button_image</item>
</style>

이 스타일을 사용하고 있습니다. 이 스타일에서 무엇을 변경해야합니까?
Nazima Kauser MMF

당신은 다시 사용자 정의 이미지 파일을 사용 button.just '@ 드로어 블 / 사진 your_image`에서 호출 할 수 있습니다
아킬 Jayakumar

이것이 최선의 방법입니다. R.drawable.abc_ic_ab_back_mtrl_am_alpha를 사용하여 색상을 변경하면 지원 버전이 드로어 블 리소스를 자주 변경하므로 위험이 있기 때문입니다.
모스 타파 이므 란

196

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>

4
매력처럼 작동했으며 가장 적절하게 들립니다.
Vijay Kumar Kanta

1
꿰매다. 효과가있다. 이제 iOS와 동등한 것이 필요합니다. 감사!
Ernesto

하지만 ToolbarTheme라고 부르는 것이 더 좋을 것입니다
Leo Droidcoder

1
저에게는 <style name = "ToolbarTheme"parent = "@ style / Theme.AppCompat.NoActionBar">가 작동했습니다. 내 주요 앱 테마는 <style name = "AppTheme"parent = "Theme.AppCompat.NoActionBar">
Yar

3
효과가있었습니다. 이것은 받아 들여진 대답보다 더 적절합니다.
Domenico

86

다음은 app:themeToolbar에 Light and Dark 테마를 구현하는 가장 간단한 방법 입니다. Toolbar 태그 의 값을 변경해야합니다.

  • 들어 블랙 도구 모음 제목블랙 위쪽 화살표 , 도구 모음은 다음과 같은 주제를 구현해야합니다 :

app : theme = "@ style / ThemeOverlay.AppCompat.Light"

검은 색 도구 모음 제목 및 위쪽 화살표

  • 들어 화이트 도구 모음 제목화이트 위쪽 화살표 , 도구 모음은 다음과 같은 주제를 구현해야합니다 :

app : theme = "@ style / ThemeOverlay.AppCompat"

흰색 도구 모음 제목 및 위쪽 화살표


66
"스타일 / ThemeOverlay.AppCompat.Dark.ActionBar @"테마 = 안드로이드 : 흰색 도구 모음 제목 및 화이트 위로는 사용 다음 테마를 화살표
아몰 파틸

이해하려고하는데 왜 ThemeOverlay라는 이름이 붙었나요? 여기서 간단한 Theme.AppCompat.Dark.ActionBar를 사용할 수없는 이유는 무엇입니까?
Gaket 2016

@ ch3tanz ActionBar 또는 Toolbar를 사용하고 있습니까? ActionBar 스타일을 사용하는 이유는 무엇입니까?
f470071

@ f470071 툴바를 사용하고 있습니다. 모든 버전에서 지원하는 스타일입니다. 앱이 Lollipop 이상을 타겟팅하는 경우 머티리얼 디자인 스타일을 사용할 수 있습니다.
ch3tanz

Theme.AppCompat.Light.DarkActionBar나의 경우에는.
Evi Song

30

흰색 도구 모음 제목 및 흰색 위쪽 화살표의 경우 다음 테마를 사용하십시오.

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

고마워요, 무엇보다도 해결은 저에게만 효과가 있습니다.
Md Juyel Rana

20

이것을 사용하십시오 :

<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="colorControlNormal">@color/white</item> 
</style>

5
이것은 받아 들여 져야합니다. 여기에있는 모든 대답은 색상이 아니라 아이콘을 대체하는 것입니다.
Michał Jabłoński

12

이 시도,

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);

6

스타일을 변경할 필요가 없습니다. 툴바를 액션 바로 설정 한 후 다음과 같이 코딩 할 수 있습니다.

android.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
android.getSupportActionBar().setHomeAsUpIndicator(R.drawable.back);
//here back is your drawable image

하지만이 방법으로는 뒤로 화살표의 색상을 변경할 수 없습니다.


6

흰색 뒤로 단추 (←)와 흰색 도구 모음 제목을 원하면 다음을 따르십시오.

<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합니다.


5

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"
Abhishek

도움이되었다.
Mohamed Nageh

4

테마가 생성되어야하는데 문제가 있다고 생각하지만 동적으로 설정된 검은 색 화살표가 있습니다.

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);

2
솔루션이 @Parth Bhayani와 어떻게 다른가요?
CoolMind

4

를 사용하고 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>

3

내가 사용하고 <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>

2

간단하고 걱정 없음

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

2

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>

작동합니다 : 햄버거 메뉴 아이콘의 색상을 변경할 수 있습니다.
lnaie

1

이 코드를 Java 클래스에 추가 할 수 있습니다. 그러나 이전에 벡터 자산을 만들어야하므로 화살표 뒤로 사용자 정의 할 수 있습니다.

actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp);

0

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>

-1

시스템 배경색 을 흰색으로 원하면 이 코드를 사용할 수 있습니다.

<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);
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.