Android Custom button with imageview and textview inside?

前端 未结 6 1959
一整个雨季
一整个雨季 2021-01-04 21:27

I\'m looking to create a custom button. This button ideally would have an image on the left and a textview on the right. How would I accomplish this?

6条回答
  •  悲&欢浪女
    2021-01-04 21:55

    Create a xml with the Layout you want, xreate a drawable which look like you want the Button to look, add the drawable as background to Linear Layout and inflate the xml to a custom view.

    Example drawable:

       
           
             
                     
                         
                         
                         
                     
             
         
             
                     
                         
                         
                         
                     
             
     
       
    

    Edit: Code to inflate

    private LayoutInflater mInflater;
    mInflater = LayoutInflater.from(this);
    public LinearLayout yourButton;
    yourButton = (LinearLayout)  mInflater.inflate(R.xml.yourButton, null);
    

提交回复
热议问题