android下的样式
Android 样式
2023-09-27 14:27:21 时间
android中控件,假如我们把样式都写死在控件的配置文件上的话。一旦改动可谓牵一发而动千军。那么我们能够把样式写在style.xml文件里。然后引用,在API14以上版本号。
该文件位于values-v14目录下。低版本号的在values目录下。
比方,我们以一个textView为例,先在style.xml文件里定义好自己的样式:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
<style name="text_content_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ff9723</item>
<item name="android:textSize">15sp</item>
</style>
</resources>
那么我们在使用控件时,能够这样引用:
<TextView
style="@style/text_content_style"
android:text="我是style文本"
/>
有了这种做法。我们非常easy想到一种经常使用的功能:夜间模式。就是把背景和文字弄成相对黑暗一点的:
<style name="text_content_style_night">
<item name="android:background">#C5C1AA</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#363636</item>
<item name="android:textSize">15sp</item>
</style>
在网页中的样式,有一个特点,就是假如写了一套CSS样式,非常多情况下都会去继承。增强代码的复用性。android的style自然也提供了这个功能。假如。我们在夜间模式中,有一个强夜间模式,就是更黑的,那么我们能够继承原来的夜间模式样式。只加深她的背景:
<style name="text_content_style_night_dark" parent="@style/text_content_style_night">
<item name="android:background">#7F7F7F</item>
</style>
至于引用样式之后。比方样式里定义了背景,控件里又又一次定义背景,那么会覆盖样式的背景。
相关文章
- Android中如何读写Word doc/ docx和PDF文件?
- 理解Android虚拟机体系结构
- android 数据持久化——I/O操作
- android开发手册!这个回答让我错失offer!小白也能看明白
- android radiogroup样式(设置切换背景与文字颜色)
- Android中自己定义checkbox样式
- 移动端开发遇到的问题以及解决方案以及开发经验(多半是样式造成的兼容性问题在Android和ios表现出入)
- Android学习路径(23)应用Fragment建立动态UI——Fragment之间的通信
- android之针对fragment多次调用onCreateView的问题
- Android Studio无法预览,缺少样式
- Android JetPack之启动优化StartUp初始化组件的详解和使用
- android中的样式和主题
- 【Android UI】绘制圆角矩形进度条 ① ( 像素值转化 dp -> px | Paint 标志位设置 | Paint 画笔线帽样式设置 | Paint 画笔线段连接处样式设置 )
- 构建 Android 应用程序一定要绕过的 30 个坑
- Android中自定义样式与View的构造函数中的第三个参数defStyle的意义
- Android PinnedSectionListView 收缩
- Android Studio关于USB device not found的解决办法
- android中透明Dialog及ProgressDialog的实现
- Android shape自定义button样式
- Centos系统下部署Android打包生成APK
- android 修改系统的dialog样式
- 成功试验基于C#/.NET的Android开发
- 我的Android进阶之旅------>Android SDK支持的配置标识符(有用的参考文件)
- Android个层次调用流程概述