Android - default button style

前端 未结 2 1757
说谎
说谎 2020-12-12 13:05

Question: Where can I find default styles xml with hexadecimal codes of colors?

I\'m looking for Style \'buttonStyle\' and other default styles witc

2条回答
  •  Happy的楠姐
    2020-12-12 13:46

    Understanding how Android styles do work can be a little bit messy.

    I will try to explain how the basic work flow would be, based on an example.

    Let's assume you want to know what the default background for buttons is. This can be either a simple color (unlikely) or a drawable (there are many different types of drawables).

    Android has Themes. A theme basically defines which style is applied to which widget. Therefore, our first step is to find the default android theme.

    You find it under android-sdk\platforms\android-15\data\res\values\themes.xml

    In this theme file, search for button.

    You will find something like this:

    
    
    @android:style/Widget.Button
    

    This means that the theme applies the style Widget.Button to buttons.

    Ok, now let's find the style Widget.Button.

    All default Android style are defined in the file android-sdk\platforms\android-15\data\res\values\styles.xml

    Now search for Widget.Button

    You will find something like this:

    
    

    The interesting line is:

    @android:drawable/btn_default

    This means that there is a drawable called btn_default set as button background.

    Now we need to find a file named btn_default.* in one of the drawable folders under android-sdk\platforms\android-15\data\res.

    This can be either an image (very unlikely) or a xml file like btn_default.xml.

    After a little bit searching you will find the file android-sdk\platforms\android-15\data\res\drawable\btn_default.xml

    It contains something like this:

    
        
        
        
        
        
        
        
    
    

    Now you have to understand that this is a selector drawable (one of the many drawable types). This selector chooses different backgrounds, based on the buttons state. For example, if the buttons is pressed, it has a different background.

    No let's look at the default state.

    It applies a drawable called btn_default_normal.

    Now we need to find this drawable.

    Again, we need to find a file named btn_default_normal.* in one of the drawable folders under android-sdk\platforms\android-15\data\res.

    This can be again either an image or a xml file like btn_default_normal.xml.

    You will find multiple files called 'btn_default_normal.9.png' in different drawable folders for different resolutions.

    :) Now you know that btn_default_normal.9.png is set as button background.

提交回复
热议问题