【发布时间】:2021-04-23 02:14:15
【问题描述】:
首先,我知道有很多关于这个问题的帖子,我想我都读过了。如果有人问我会附上他们批准:)
我对 attrs 有疑问。问题是有时我看到程序员在创建 自定义视图 时使用它,但有时我看到它们也在构建主题时使用。 例如:
<declare-styleable name="Main_Theme">
<attr name="background" format="reference" />
<attr name="backgroundCard" format="reference" />
<attr name="secondaryTextColor" format="reference" />
<attr name="primaryTextColor" format="reference" />
<attr name="primaryColor" format="reference" />
<attr name="secondaryColor1" format="reference" />
<attr name="secondaryColor2" format="reference" />
<attr name="secondaryColor3" format="reference" />
<attr name="dividerColor" format="reference" />
然后他们使用它创建一个主题。 例如:
<item name="background">@color/dark_theme_background</item>
<item name="backgroundCard">@color/dark_theme_card_background</item>
<item name="secondaryTextColor">@color/dark_theme_scores_new</item>
<item name="primaryTextColor">@color/dark_theme_primary_text_color</item>
<item name="primaryColor">@color/dark_theme_primary_color</item>
<item name="secondaryColor1">@color/dark_theme_secondary_1_color</item>
<item name="secondaryColor2">@color/dark_theme_secondary_2_color</item>
<item name="secondaryColor3">@color/dark_theme_secondary_3_color</item>
<item name="dividerColor">@color/dark_theme_divider_color</item>
然后我看到他们使用这些项目作为布局活动 xml 文件中的属性值 所以我真的无法理解 attrs 的各种用途。 我希望有人能帮助我理解因为我感到很困惑
【问题讨论】: