Android Button with text and image

前端 未结 4 1219
温柔的废话
温柔的废话 2021-01-21 10:04

After seeing many questions for this feature and attempting to follow the answers, I was left wondering if there was a clearer example to be had?

Edit: I was attempting

4条回答
  •  难免孤独
    2021-01-21 10:25

    In an attempt to save others some time, I offer this:

    layout/some_layout.xml

    
    
        android:background="@drawable/btn_std_holo_states"
        
        android:clickable="true"    
        
        android:minHeight="48dp"    
        
        android:onClick="onClickOk" >   
    
        
        
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            
            android:drawableLeft="@drawable/ic_ok"
            
            android:drawablePadding="16dp"
            
            android:gravity="center"
            
            android:text="@android:string/ok"
            
            android:textAppearance="?android:attr/textAppearanceButton" />
    
    
    

    drawable/btn_std_holo_states.xml (referenced above)

    
    
    
        
        
        
        
    
    
    

    NOTE: the different @drawable and @android:color settings here can be anything and are only provided to make a complete example

提交回复
热议问题