Android样式(style)和主题(theme)资源介绍-android学习之旅(五十六)

本文深入探讨了在Android应用开发中如何通过XML资源文件自定义样式和主题,具体展示了如何创建样式资源,以及如何将这些样式应用于EditText组件中,包括设置文本大小、颜色和背景。此外,还介绍了如何继承和修改样式来实现个性化UI设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

样式(style)资源

这里写图片描述
这里写图片描述

代码示例

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
   <EditText
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="hello world"
       style="@style/style1"/>
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="hello world"
        style="@style/style2"/>
</LinearLayout>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>
    <style name="style1">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">#00d</item>
    </style>
    <style name="style2" parent="@style/style1">
        <item name="android:background">#ee6</item>
        <item name="android:padding">8dp</item>
        <item name="android:textColor">#000</item>
    </style>
</resources>

主题资源

这里写图片描述
这里写图片描述
这里写图片描述

转载于:https://www.cnblogs.com/fengsehng/p/6048582.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值