简体   繁体   English

Android-具有图片+背景+文字的按钮

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

I have a button, the button has a background and a src Image icon. 我有一个按钮,该按钮有一个背景和一个src图像图标。 Now I want to have a text on the bottom, inside my button. 现在,我想在按钮底部的底部显示一个文本。

How can I achieve this? 我该如何实现?

I cannot use ImageButton as it doesn't handle text. 我不能使用ImageButton,因为它不处理文本。 Also I cannot use Button as it doesn't handle src Image. 我也不能使用Button,因为它不能处理src图像。

Try this.. 尝试这个..

Use android:drawableTop="@drawable/ic_launcher" 使用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" />

Or 要么

        <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 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