我是 android 新手..请指导我..
我想设置图像作为按钮..
如何在xml和类文件中实现这个?
我现在在 xml 和类文件中设置按钮的代码是这样的..
<Button android:id="@+id/nxt_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/rdtxt" android:layout_marginRight="22dp" android:layout_marginTop="34dp" android:text="Next" />
Button nextBtn = (Button) findViewById(R.id.nxt_btn);
我想要 practice.png 这个图像想充当按钮..我已经把这个图像放到 drawables 中..
现在如何通过代码实现这个...请指导我...
非常感谢...
最佳答案
在xml中你可以添加:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />
在 Activity 中:
ImageView image = (ImageView) findViewById(R.id.image);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//Do your stuff here
}
});
关于android - 如何在 xml 和类中将图像设置为按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14751761/