我有非常简单的问题,如何在自定义按钮中添加图像?如何将图像添加到自定义按钮
<com.example.KeyButton
android:id="@+id/custombutton"
android:layout_gravity="center_vertical"
android:layout_height="fill_parent" />
我有非常简单的问题,如何在自定义按钮中添加图像?如何将图像添加到自定义按钮
<com.example.KeyButton
android:id="@+id/custombutton"
android:layout_gravity="center_vertical"
android:layout_height="fill_parent" />
添加这个标签android:background="@drawable/your_image"
<com.example.KeyButton
android:id="@+id/custombutton"
android:layout_gravity="center_vertical"
android:layout_height="fill_parent"
android:background="@drawable/your_image" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/yourImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image" />
</LinearLayout>
并把 “your_image” 中绘制文件夹。
您必须添加android:backgroud添加图片。
<com.example.KeyButton
android:id="@+id/custombutton"
android:layout_gravity="center_vertical"
android:layout_height="fill_parent"
android:background"@drawable/image" /> //here will be your image.
在drawble文件夹按钮,放像,并把你的XML文件中的代码....
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<Button
android:id="@+id/btn_your_btn_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/set_alarm_button" />
</LinearLayout>
希望这将有助于。
您可以通过编程使用方法:
setBackground(Color c); and
setBackground(Drawable d);
setBackgroundResource(int resId);
否则,您可以使用XML的方式像上面
使用'机器人说:background' –
相同的方式,在''ImageView'的Android添加图片:背景= “@可绘制/图像”。 – GrIsHu
thanx为您的答复,但我喜欢像图像按钮视图有PNG图像。 – vik