[android] 安卓自定义样式和主题

简单练习自定义样式和主题,样式是加在View上,主题是加在Application或者Activity上

styles.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 自定义样式 -->
    <style name="MyFont">
        <item name="android:textColor">#ff0000</item>
        <item name="android:textSize">40sp</item>
    </style>
    <style name="MyFontSon" parent="@style/MyFont">
        <item name="android:textSize">30sp</item>
    </style>
    <!-- 自定义主题 -->
    <style name="MyTheme">
        <item name='android:windowNoTitle'>true</item>
        <item name="android:background">#ffffff</item>
    </style>
</resources>
复制代码

activity_main.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
        style="@style/MyFont"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="样式和主题"
        />
    <TextView
        style="@style/MyFontSon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="样式和主题"
        />
</LinearLayout>
复制代码

Manifest.xml

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="ss"
        android:theme="@style/MyTheme" >

posted @   唯一客服系统开发笔记  阅读(574)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示
1
chat with us