簡體   English   中英

Android-具有圖片+背景+文字的按鈕

[英]Android - A button with Image + background + text

我有一個按鈕,該按鈕有一個背景和一個src圖像圖標。 現在,我想在按鈕底部的底部顯示一個文本。

我該如何實現?

我不能使用ImageButton,因為它不處理文本。 我也不能使用Button,因為它不能處理src圖像。

嘗試這個..

使用android:drawableTop="@drawable/ic_launcher"

       <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:text="Button" />

要么

        <RelativeLayout
            android:id="@+id/btn_lay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_margin="5dp"
                android:gravity="center"
                android:text="Cal" />
        </RelativeLayout>

ClickListener

 RelativeLayout btn_lay = (RelativeLayout) findViewById(R.id.btn_lay);

 btn_lay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                        // Do Something
        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM