How to show the text on a ImageButton?

后端 未结 11 1419
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 08:42

I have an ImageButton and I want to show a text and an image on it. But when I try on emulator:



        
相关标签:
11条回答
  • 2020-12-04 09:31

    you can use a regular Button and the android:drawableTop attribute (or left, right, bottom) instead.

    0 讨论(0)
  • 2020-12-04 09:32

    You can use a LinearLayout instead of using Button it's an arrangement i used in my app

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:background="@color/mainColor"
            android:orientation="horizontal"
            android:padding="10dp">
    
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:background="@drawable/ic_cv"
                android:textColor="@color/offBack"
                android:textSize="20dp" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="@string/cartyCv"
                android:textColor="@color/offBack"
                android:textSize="25dp" />
    
        </LinearLayout>
    
    0 讨论(0)
  • 2020-12-04 09:32

    Heres a nice circle example:

    drawable/circle.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
    
        <solid
            android:color="#ff87cefa"/>
    
        <size
            android:width="60dp"
            android:height="60dp"/>
    </shape>
    

    And then the button in your xml file:

    <Button
        android:id="@+id/btn_send"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:background="@drawable/circle"
        android:text="OK"/>
    
    0 讨论(0)
  • 2020-12-04 09:35

    It is technically possible to put a caption on an ImageButton if you really want to do it. Just put a TextView over the ImageButton using FrameLayout. Just remember to not make the Textview clickable.

    Example:

    <FrameLayout>
        <ImageButton
            android:id="@+id/button_x"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/button_graphic" >
        </ImageButton>
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"
            android:text="TEST TEST" >
        </TextView>
    </FrameLayout>
    
    0 讨论(0)
  • 2020-12-04 09:35

    Guys I need to develop the setting and logout button, I used the below code.

        <Button
            android:id="@+id/imageViewLogout"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/size_30dp"
            android:layout_alignParentLeft="true"
            android:text="Settings"
            android:drawablePadding="10dp"
            android:background="@android:color/transparent"
            android:layout_alignParentBottom="true"
            android:drawableTop="@drawable/logout" />
    
    0 讨论(0)
提交回复
热议问题