Android Studio:如何快速将样式从 layout.xml 移动到 style.xml?
Android Studio: How to quickly move styling from layout.xml to style.xml?
代码块 1:我在 view.xml
中有以下代码
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="@string/hello" />
代码块 2: 现在我想把它改成这样的样式。
<TextView
style="@style/CodeFont"
android:text="@string/hello" />
代码块 3:在我的 styles.xml 文件中,我想要这个。
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
将所有这些属性包装在 <item name="XXX"/>
标记中是一个非常手动且烦人的过程。 Android Studio 是否有某种类型的魔法可以自动将代码块 1 中的属性转换为代码块 3 中的项目标签?
在编辑 TextView
时(在布局 .xml
文件内)按 Ctrl+Shift+A 并输入 extract
。您需要的商品是 Style...
.
代码块 1:我在 view.xml
中有以下代码<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="@string/hello" />
代码块 2: 现在我想把它改成这样的样式。
<TextView
style="@style/CodeFont"
android:text="@string/hello" />
代码块 3:在我的 styles.xml 文件中,我想要这个。
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
将所有这些属性包装在 <item name="XXX"/>
标记中是一个非常手动且烦人的过程。 Android Studio 是否有某种类型的魔法可以自动将代码块 1 中的属性转换为代码块 3 中的项目标签?
在编辑 TextView
时(在布局 .xml
文件内)按 Ctrl+Shift+A 并输入 extract
。您需要的商品是 Style...
.