Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate style from xml in intellij (/android studio)

Is there a way how to generate style from XML attributes so I don't have to manually copy paste 1 by 1? When I prototype, I use the "inline" styles then I want to export styles into styles.xml but manually it is time consuming task. It is just different format, should be easy to automate.

<ImageView
        android:layout_width="80dp"
        android:layout_height="47dp"/>

into

<ImageView
        style="@style/h2_image"/>

<style name="h2_image">
    <item name="android:layout_width">80dp</item>
    <item name="android:layout_height">47dp</item>
</style>
like image 549
Srneczek Avatar asked Jun 21 '16 12:06

Srneczek


People also ask

Where is my styles XML in Android Studio?

Defining Styles This XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file.

Where do you create styles in XML?

To define a style, save an XML file in the /res/values directory of your project. The root node of the XML file must be <resources> .

What is the use of style .XML in Android?

Styles in Android allow you to define the look and feel, for example colors and fonts, of Android components in XML resource files. This way you have to set common style attributes only once in one central place.

How do I create a style folder in Android?

You have to create a value folder with values-v21 caption. and create style. xml file in this with the same name as values folder like styles. xml.


1 Answers

Very Simple.!

Just keep the cursor in the file from where you want to extract the style resource. Just a right click then click on refactor.

Refactor -> Extract -> style/layout.

This bow will apear

Then give style a name and there you go..! For more you can refer the documentation.

like image 76
Archit Garg Avatar answered Oct 27 '22 01:10

Archit Garg