我认为您需要将复选框与组而非普通按钮视图一起使用。如果不清楚,我可以为您编写一些代码.. 但基本上您将使用复选框并更改样式以同意您要显示的内容.. 在这种情况下,您将能够突出显示(检查)并单击其他button(checkbox) 如果你在一个组中使用所有它们,第一个检查将消失
=======添加代码=======
我的朋友来了:
关于主要活动:
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class HighListButtonActivity extends Activity implements OnCheckedChangeListener {
private CheckBox b1,b2,b3;
private int selectedChId=-1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1=(CheckBox)findViewById(R.id.ck1);
b2=(CheckBox)findViewById(R.id.ck2);
b3=(CheckBox)findViewById(R.id.ck3);
b1.setOnCheckedChangeListener(this);
b2.setOnCheckedChangeListener(this);
b3.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// here just to follow the checkbox which is checked to uncheck it later when other checkbox is checked..
if(selectedChId==-1){
selectedChId=buttonView.getId();
}else if(selectedChId==buttonView.getId()){
selectedChId=-1;
}else{
((CheckBox)findViewById(selectedChId)).setChecked(false);
selectedChId=buttonView.getId();
}
//make your logic here......
}
}
main.xml:
<?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" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bt1"
android:button="@drawable/hlor"
android:background="@drawable/hlor"
android:id="@+id/ck1"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bt2"
android:button="@drawable/hlor"
android:background="@drawable/hlor"
android:id="@+id/ck2"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bt3"
android:button="@drawable/hlor"
android:background="@drawable/hlor"
android:id="@+id/ck3"
/>
</LinearLayout>
hlor.xml(作为选择器样式):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/hlord" />
<item android:state_checked="false" android:drawable="@drawable/hlornd" />
</selector>
hlord.xml(作为检查样式drawable):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<android:solid android:color="#FF555555"/>
</shape>
</item>
</layer-list>
hlornd.xml(作为未选中样式drawable):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<android:solid android:color="#FF000000"/>
</shape>
</item>
</layer-list>
为了突出显示只需更改 hlornd/hlord 样式的颜色
祝你好运……