Drawables
android:selectableItemBackground
android:listChoiceIndicatorSingle
主要提供一些特殊的背景效果,例如 button 在不同状态的点击效果
Themeception
android:actionBarTheme
android:dialogTheme
这个随后给大家分享
Styles
是用于定于视图样式的一系列的值
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:background="@drawable/my_drawable"
/>
这里我们为 ImageView 定义了背景,如果我们想将该背景抽出为 style 以便复用。
<style name="MyStyle">
<item name="android:background">
@drawable/my_drawable
</item>
</style>
然后修改 ImageView
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
style="@style/MyStyle"
/>
Android studio 提供了提取组件样式来作为 style 使用功能,这样大大地方便了开发人员。在设计设图中选择一个要提取 style 的组件,然后右键单击,在弹出菜单中选择 Refactor 然后选择 Extract Style... ,
完成上面操作,会看到一个 Extract Android Style 对话中,显示了该组件所有的可以提取属性。
我们可以选择要提取到 style 的属性,然后 style name 输入一个 style 名称这样单击 OK 就完成提取
这样我们在 style.xml 文件中就可以看到生成的样式。
style 继承
<style name="MyStyle">
<item name="android:background">
?android:attr/selectableItemBackground
</item>
</style>
这里? 表示在 theme 进行查找,android: 表示在 android 命名空间内进行查找,attr/表示我们查找的类型为 attr 这里可以省略,最后 selectableItemBackground 表示我们要查找的属性。
网友评论