java - Android:Theme.xml 和 Styles.xml?
问题描述
在较新版本的 Android Studio 中,我看不到,但是在 values 目录中,styles.xml
有两个新的XML和.theme.xml
theme.xml(night)
它实际上是否取代了styles.xml
OR如果不同的工作,它们之间有什么区别?
解决方案
样式是属性的集合,它定义了某个 ui 的外观例如:editText 或 textView一个主题同时决定了整个应用程序的外观(单个主题可以有多种样式取决于您的设计),白天和晚上主题之间的区别就是让你的app适应白天模式和夜间模式。因为现在在 android OS 中,您可以强制使用暗模式。
作为开发人员,您需要为此准备好您的应用程序。
如何使用这个
为项目中标记的两个主题赋予不同的颜色(以下来自主题文件)
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.<Your app name>" <---- this is autogenrated this wil be the id to be used
parent="Theme.MaterialComponents.DayNight">
</style>
</resources>
要在 textview 或按钮或布局文件中使用,只需:
<TextView
android:id="@+id/tv_StackOverflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Theme.<Your app name>" /> <---insert your style name inside the theme.
现在,当用户在手机的开发者模式下强制打开暗模式时,您的应用程序将立即适应它并更改其 UI 的颜色。
更多信息可以在这里找到 - https://developer.android.com/guide/topics/ui/look-and-feel/themes
推荐阅读
- javascript - 有没有办法在下午提到角色?不和谐.js
- python - 如何比较2个数据框之间的值
- vue.js - Google Pageinsight LCP 问题仅在移动设备上(Vuejs)
- kotlin - 从 Kotlin 中的字符串中提取多个整数
- agora.io - Agora.io RTM 是否提供打字状态?
- airflow - prometheus 和 grafana 的气流指标
- android - Android 通过接入点在 LAN 上使用 Rest API
- amazon-web-services - 如何删除在 AWS Elastic Beanstalk 中创建的 CNAME 映射
- android-listview - 如何在 ListView (Android Studio) 中显示每个项目的完整内容?
- java - 如何为android中的每个EditText设置单独的验证?