专注于点击按钮

时间:2011-08-17 09:14:04

标签: android button focus onclick drawable

是否可以将按钮的图像突出显示或更改为另一个图像Onclick()按钮?

这是我的按钮

的xml
     <Button android:layout_height="wrap_content"
     android:textColor="#000000" 
    android:gravity="center_horizontal|center_vertical" android:layout_gravity="center_horizontal|center_vertical"
     android:focusableInTouchMode="true"
     android:background="@drawable/button"
     android:layout_width="wrap_content" 
    android:soundEffectsEnabled="true" 
    android:text="START" 
    android:focusable="true"
     android:id="@+id/start"></Button

>

2 个答案:

答案 0 :(得分:1)

是的,你可以,首先使用findViewById()方法获取两个按钮的引用,然后执行此操作

button1.setOnclickListener(new OnClickListener(){

protected void onClick(View v){


button2.setBackground(Color.WHITE);

}
});

修改

override another method.

button1.setOnFocusChangedListener(new OnFocusChangedListener(){

protected void onFocusChange()
{
button2.setBackground("your 1st image")
}
});

答案 1 :(得分:0)

您可以使用setImageRessource方法:

ImageButton.setOnclickListener(new OnClickListener(){

protected void onClick(View v){


imageButton.setImageResource(R.id.newImage)

}
});