Development Tip

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

yourdevel 2020. 10. 30. 21:08
반응형

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


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

감사합니다


이 스타일 사용

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

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


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

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

위의 모든 제안을 시도했습니다. 내 도구 모음에서 탐색 아이콘 기본 뒤로 버튼 화살표의 색상을 변경하는 유일한 방법은 colorControlNormal이와 같은 기본 테마 를 설정 하는 것입니다. 아마도 부모가 사용하고 있다는 사실 때문일 것입니다.Theme.AppCompat.Light.NoActionBar

<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="colorControlNormal">@color/white</item> 
  //the rest of your codes...
</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);

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

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

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

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

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

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


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

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


<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="colorControlNormal">@color/white</item> 
  //your code
</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>

시스템 백 컬러 를 흰색으로 원하면 이 코드를 사용할 수 있습니다.

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

참고 URL : https://stackoverflow.com/questions/33339043/how-to-change-color-of-toolbar-back-button-in-android

반응형