2011-08-17 92 views
0

是否可以将按钮的图像突出显示或更改为其他图像Onclick()按钮?专注于单击按钮

这是肯定的,你可以先得到使用两个按钮的参考findViewById()方法我对按钮

 <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 

> 

回答

1

XML,然后做这个

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") 
} 
}); 
+0

@绘制/按钮包含我想设置为我的按钮背景图像的图像......与按钮的onclick我想为一小部分的图像说明更改@ drawble /红..请帮助 – SKB

+0

你可以进行相同的过程..它会工作得很好.. – ngesh

+0

好吧..很好,当我这样做,我将能够完全改变图像...并不恢复到最初的形象... – SKB

0

你可以使用setImageRessource m ethod:

ImageButton.setOnclickListener(new OnClickListener(){ 

protected void onClick(View v){ 


imageButton.setImageResource(R.id.newImage) 

} 
}); 
+0

我试图使用图像按钮..但无法在图像按钮上设置文本...是否可以在图像按钮中设置文本? – SKB