Button highlight in android

后端 未结 5 1749
星月不相逢
星月不相逢 2021-02-08 23:59

I have the following code for a button in the layout file for my application

5条回答
  •  梦毁少年i
    2021-02-09 00:00

    A button has a set of states that can be configured like this:

    
    
        
        
    
    

    You can create this as a file in your res/drawables folder and then use it in your button as the background. Supose that you called that file "my_button.xml" you can then use it like this:

    Or like this:

    my_button.setBackgroundDrawable(getResources().getDrawable(R.drawable.my_button));
    

    Your color can be defined in the colors.xml in the res/values folder. If you don't have this file you can create it (android will recognize it). This is a good practise, but you can also replace your_color by #DC143C in the code above.

    
    
        #DC143C
    
    

    Note that this color is already set for crimson.

    You can also add an image for the background, replacing the "@color/your_color" by "@drawable/your_image".

    For more information you can follow this link in stackoverflow.

提交回复
热议问题