Android Studio : How to quickly move styling from layout. xml 到 style.xml?

标签 android xml android-layout android-studio android-styles

代码块 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...

关于Android Studio : How to quickly move styling from layout. xml 到 style.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28302994/

相关文章:

android - 以编程方式设置样式不起作用?

java - 使用 html 更改 XML 值

ios - 解析位于项目内部的 XML

python - 如何修复 PyXML?

android - 自定义 View 可以用作 TabItem 吗?

android - 仅限 API 23 以下的相机权限

android - 如何开启特定的第三方 Activity ?

android - 如何在TabLayout android上的 Activity 中获取选项卡单击事件

android - 如何在 Android 上上传 Firefox OS 应用程序

android - 如何在填充列表后以编程方式更改列表元素的高度