Android - 覆盖 android 布局文件中的样式

标签 android android-layout android-styles

我经常在 android 中看到这样的布局文件:

<?xml version="1.0" encoding="utf-8"?>    
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeightSmall"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:gravity="center_vertical"
        android:checkMark="?android:attr/listChoiceIndicatorMultiple"
        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    />

这实际上是 android.R.layout.simple_list_item_multiple_choice 布局文件。

我想知道的是,如果我在我的应用程序中使用这个布局,有没有办法在我的 styles.xml 中覆盖这个文件中提到的属性。因此,例如,我想为 checkMark 定义一个可绘制对象,我可以在我的应用程序主题或 styles.xml 文件中这样做吗?如果是这样,如何?现在我只是复制这些文件并根据需要更改属性。

最佳答案

是的,这是可能的。 你只需要在你的主题中覆盖这个样式属性。例如,如果你想更改勾选标记:

android:checkMark="?android:attr/listChoiceIndicatorMultiple"

在你的主题中加入以下内容:
<item name="android:listChoiceIndicatorMultiple">@drawable/your_custom_selector_for_check_mark</item>

您可以使用此网站创建资源和选择器 http://android-holo-colors.com/

关于Android - 覆盖 android 布局文件中的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16053603/

相关文章:

android - 我可以从 Dart 调用 Kotlin 函数吗

android - 我们可以在 android 键盘中同时拥有 Go 和 Next 按钮吗

android - 如何正确缩放开关小部件的自定义拇指?

android - 如何去除 DatePickerDialog 中多余的空格(在 Android M & N 上看到)?

android - 我可以将我的 Android 样式放在不同的包名称中吗?

导航栏上方的android Q内容

android - 使用命令行和 Gradle 签名的 apk

java - RequestParams params.put 方法未接收整数

android - fragment 选项卡中的框架布局

android - 警报对话框大小