一手遮天 Android

项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd

一手遮天 Android - UI: 通过主题修改控件的默认样式

示例如下:

/ui/ThemeDemo3.java

/**
 * 通过主题修改控件的默认样式
 */

package com.webabcd.androiddemo.ui;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import com.webabcd.androiddemo.R;

public class ThemeDemo3 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 指定 activity 的主题(需要在 setContentView() 之前)
        setTheme(R.style.ThemeDemo3Theme);

        setContentView(R.layout.activity_ui_themedemo3);
    }
}

/layout/activity_ui_themedemo3.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!--
        本例用于演示如何通过主题修改控件的默认样式(控件的默认样式将使用指定主题中的样式)
    -->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是 TextView"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是 Button" />
</LinearLayout>

项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd

原文地址:https://www.cnblogs.com/webabcd/p/android_ui_ThemeDemo3.html