[STYLE&THEME]
   css같은거

 

THEME
   테마 - 스타일을 모아서 전체  에 적용

themes.xml 에가서 기본 테마 값들을 변경할 수도 있고 내가 커스텀해서 변경 할 수도 있음  

(여기서는 값만 세팅하고

 manifestes > AndroidManifest.xml 요기랑 MainActivity.java 에서 적용하는 것 같음)

 [디폴트 - 기본 메인적용& 액션바 없애기]

 

1.xml파일설정

 

1-1.themes.xml

<style name="Theme.StyleTheme08" parent="Theme.MaterialComponents.DayNight.NoActionBar">

1-2.AndroidManifest.xml

android:theme="@style/Theme.MaterialComponents.NoActionBar"

2.자바코드로 없애기

getSupportActionBar().hide();
setContentView(R.layout.activity_main);

 

[내가만든 테마 적용하기]

themes.xml에 내가만든 스타일을테마로 적용 (자바코드로)
setTheme()
내가 만든 리소스는 R.java(R클래스)에 자동으로 등록됨
내가만든 자원은 R.리소스종류로 접근한다.

(cf.안드로이드에서 제공하는 리소스 사용 시는
     자바코드: android.R시작 레이아웃용

     xml:@android로 시작)

 

 

themes.xml

<!-- Customize your theme here. -->
<style name="Theme.MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
   <!--글자색은 흰색-->
    <item name="android:textColor">#ffffff</item>
    <!--배경색-->
    <item name="android:background">#E8C45A</item>
    <!--글자크기-->
    <item name="android:textSize">18sp</item>
</style>

<!--위의 내가 만든 스타일 상속  =>요거도 가능하네-->
<style name="Theme.MyThemeChild" parent="Theme.MyTheme">
    <!--글자크기 오버라이딩-->
    <item name="android:textSize">25sp</item>
    <!--패딩-->
    <item name="android:paddingBottom">40dp</item>
</style>

 

AndroidManifest.xml

android:theme="@style/Theme.MyTheme"

 

MainActivity.java

 setTheme(R.style.Theme_MyThemeChild);   //자바코드가 우선이라서 다 무시되고 이게 적용 됨 !

[STYLE]

 스타일 - 특정 위젯/뷰

스타일 적용 순위
위젯의 스타일 > 앱의 테마
 즉 android:textColor를 위젯과 앱의 테마에 동시 지정 시
 젯에 지정한 스타일이 우선한다

   [ 안드로이드에서 제공하는 스타일을 위젯에 적용]

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp"
    android:text="텍스트 스타일(색상 및 크기 등 미지정)"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView"
    style="@style/TextAppearance.AppCompat.Headline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="34dp"
    android:text="안드로이드 제공 스타일:스타일 적용"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.703"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

 

[내가 만든 스타일을 위젯에 적용]

테마가 MaterialComponents일때 버튼은 백그라운드가 적용이 안된다.
즉MaterialComponents테마는
button자체적으로 별도의 background가 적용되어 있어서 바꿀 수 없다
아래 두 가지 설정으로 배경색을 설정 할 수 있있다
         backgroundTint로 색상 설정
         backgroundTintMode로 add 설정

 

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="44dp"
    android:backgroundTint="@color/my_button_color"
    android:backgroundTintMode="add"
    android:text="테마적용(텍스트 색상 및 크기)"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

'학원 > ANDROID' 카테고리의 다른 글

01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07
01/05 77-2 [Android] GridLayout /LayoutExam  (1) 2023.01.07
01/05 77-1 [Android] FrameLayout  (1) 2023.01.07
01/04 76-4 [Android] TableLayout  (0) 2023.01.04

+ Recent posts