Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Code Block 1: I have the below code in view.xml

<TextView     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:textColor="#00FF00"     android:typeface="monospace"     android:text="@string/hello" /> 

Code Block 2: Now I want to move it to a styling like this.

<TextView     style="@style/CodeFont"     android:text="@string/hello" /> 

Code Block 3: In my styles.xml file, I want to have this.

<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> 

Wrapping all those attributes in an <item name="XXX"/> tag is a very manual and annoying process. Does Android Studio have some type of wizardry to automatically convert the attributes from code block 1 into the item tags from code block 3?

like image 624
ZakTaccardi Avatar asked Feb 03 '15 15:02

ZakTaccardi


People also ask

How do I move XML from one file to another in Android?

[1] call startActivity to open another layout. startActivity(new Intent(getApplicationContext(), _second. class)); [2] Create another XML layout file which you want to display.

Is style XML and theme XML same?

no it doesn't explain the difference between the two files, it only explaind the difference in the concept. However it is probably not more complicated, as in most examples we see that you put "MyTheme" in styles. xml, and you use it as a theme in the manifest.

Where are styles created in XML?

Create and apply a style To create a new style or theme, open your project's res/values/styles. xml file. For each style you want to create, follow these steps: Add a <style> element with a name that uniquely identifies the style.

How do I find styles in XML?

xml file in the new Android Studio. Goto your project file view: Res>Values>Themes folder. Open themes. xml file change actionbar.


1 Answers

While editing your TextView (inside the layout .xml file) press Ctrl+Shift+A and type extract. The item you need is Style....

like image 55
Egor Neliuba Avatar answered Oct 11 '22 12:10

Egor Neliuba