안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong

package com.example.a15u560.myapplication; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { Button buttonEvent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonEvent = (Button)findViewById(R.id.buttonEvent); buttonEvent.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if(motionEvent.getAction() == MotionEvent.ACTION_DOWN) { buttonEvent.setBackgroundColor(Color.TRANSPARENT); } else if(motionEvent.getAction() == MotionEvent.ACTION_UP) { buttonEvent.setBackgroundColor(Color.LTGRAY); } return false; } }); } }

안드로이드 버튼의 기본 색상은 퍼플 입니다.
values/themes/themes.xml 정의를 보면 하기 와 같이 퍼플 컬러값이 지정되어 있습니다.
colorPrimary 를 바꾸게 되면 기본 버튼의 색상이 바뀌게 되지만, colorPrimary 로 등록된 주요 UI 부분의 색상이 모두 바뀌기 때문에 버튼별 색상값을 바꾸는 것이 좋아보입니다.

 <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>

colorPrimary 는 앱바 및 다른 주요 UI 구성요소의 색상 값이라고 정의 되어 있습니다.(안드로이드 개발자 페이지)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--   color for the app bar and other primary UI elements -->
    <color name="colorPrimary">#3F51B5</color>

    <!--   a darker variant of the primary color, used for
           the status bar (on Android 5.0+) and contextual app bars -->
    <color name="colorPrimaryDark">#303F9F</color>

    <!--   a secondary color for controls like checkboxes and text fields -->
    <color name="colorAccent">#FF4081</color>
</resources>

버튼 색상은 backgroundTint 속성에서 간단히 변경할 수 있습니다.

안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong

버튼 색상 수정 전후의 모습 입니다.

안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong
안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong


감사합니다

최근에는 BackgroundTint 만 수정해도

버튼 색상이 바뀐다.  관련내용은 하기 내용을 참고드립니다.

감사합니다.

https://soo0100.tistory.com/1864

안드로이드 버튼 색상 바꾸기

안드로이드 버튼의 기본 색상은 퍼플 입니다. values/themes/themes.xml 정의를 보면 하기 와 같이 퍼플 컬러값이 지정되어 있습니다. colorPrimary 를 바꾸게 되면 기본 버튼의 색상이 바뀌게 되지만, colorP

soo0100.tistory.com

안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong

+++

최근 안드로이드 스튜디오가 업데이트 되면서

버튼의 기본 색상이 보라색으로 바뀌었다.

그대로 써도 무방하지만 그래도 회색음영의 이전 기본 색상이 더 좋아보였던거 같다.

기본 보라색 버튼 색상을 바꾸어 보자.

안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong
버튼 위젯 기본 색상 - 보라색

Background 색상 값만 바꾸어서는 버튼 색상 값이 바뀌지 않는다.  

안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong

BackgroundTint 도 수정을 해야 한다.

필자는 흰색을 적용 했고, 회색 음영의 버튼 값을 없었다.

안드로이드 버튼 색 변경 - andeuloideu beoteun saeg byeongyeong

사실 Tint 라는 개념은 안드로이드 개발자 사이트에서 찾아본 결과,

색상을 섞는 개념이다.  즉, Background 에 이미지나 기본 컬러를 설정하고 그 배경에 Tint 색상을 하기 모드로 설정하여 색상 값을 표현한다는 의미이다.

사실 하기 옵션값을 다 이해하지는 못했다.

android:backgroundTintMode

Blending mode used to apply the background tint.

Must be one of the following constant values.

ConstantValueDescription

add 10 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiply e Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen f [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop 9 The tint is drawn above the drawable, but with the drawable?s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in 5 The tint is masked by the alpha channel of the drawable. The drawable?s color channels are thrown out. [Sa * Da, Sc * Da]
src_over 3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

하지만, 백그라운드 와 Tint 값을 조정하면 

내가 원하는 색상을 편히 얻을 수 있는 기본 개념만 알고 있다면

큰 문제는 되지 않을 듯 하다. 다만 테스트가 필요할 뿐 ^^

android:background

A drawable to use as the background. This can be either a reference to a full drawable resource (such as a PNG image, 9-patch, XML state list description, etc), or a solid color such as "#ff000000" (black).

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

android:backgroundTint

Tint to apply to the background.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

해당 포스팅에서

부연 설명을 주실 분들은 댓글 부탁드립니다.

저도 포스팅 하면서 고치고, 배우고 업데이트 하겠습니다.

안드로이드 스튜디오에서 갑자기

버튼이 보라색이 되었다고 놀라지 마시고 편히 바꾸어 주세요

감사합니다.