The application has a TextView and for them I set up the shadows, color and thickness like this

 android:shadowColor="@color/black_color" android:shadowDx="2" android:shadowDy="2" android:shadowRadius="5" android:textStyle="bold" android:textColor="@color/ntz_color_yellow" 

Then I twist the elements more and more, and now it’s no longer convenient for everyone to write an extra 6 lines.

How can this be brought to style? How to find values ​​in styles that correspond to values ​​that you write in XML for a view?

    1 answer 1

    In the file res / values ​​/ styles.xml you add your style:

     <style name="styleMyButton" parent="android:style/Widget.Button"> > <item name="android:background">@drawable/custom_background_selector</item> <item name="android:padding">12dp</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_width">wrap_content</item> <item name="android:textSize">24sp</item> </style> 

    Values ​​in styles correspond to attribute names. It is best to inherit the style from the View for which this style will be applied - this will allow you to "pick up" the attributes by default. Here is the inheritance from the style for the Button

    Then use:

     <Button android:id="@+id/button1" style="@style/styleMyButton" android:text="@string/text_button1"/> <Button android:id="@+id/button2" style="@style/styleMyButton" android:text="@string/text_button2"/> 

    It will not be superfluous to examine the Android framework (and \ or AppCompat library , if it is used) in the styles.xml file to find out all the attributes available for redefinition (to change default values), so you can naturally add your own attributes.
    You can also access the system's styles.xml files directly in the IDE in a way similar to this answer , just follow the res / values ​​/ folder