我有4个按钮在我的布局,现在每当我点击任何按钮,之后的点击事件,按钮应该突出显示它是最后点击。
为了制造这样的东西,我尝试了以下几点:
代码:
btn1.setOnClickListener(new button_click_listener());
btn2.setOnClickListener(new button_click_listener());
class button_click_listener implements Button.OnClickListener
{
@Override
public void onClick(View v)
{
if(v==btn1)
{
btn1.requestFocus();
}
if(v==btn2)
{
btn2.requestFocus();
}
.......
}
}XML布局:
<Button
android:text="Click 1"
android:id="@+id/btnClick1"
android:layout_width="70dp"
android:layout_height="wrap_content"
style="@android:style/Widget.Button.Small"
android:padding="10dp"
android:focusableInTouchMode="true">
</Button>如何在最后单击的按钮上显示单击的高亮显示?请给我一条路,给我一些建议。
更新:
如果我设置了android:focusable="true"然后按钮被高亮显示并聚焦,但同时,我需要在按钮上点击两次来执行实际的单击事件。
发布于 2011-01-13 12:38:43
它很简单,buddy...just,您必须设置背景颜色,您的按钮,在您单击事件,每次单击任何按钮,您必须设置其他按钮,背景颜色为空。
发布于 2012-04-14 06:41:30
此功能类似于RadioButtonGroup,根据您的需求自定义RadioButtonGroup。
通过以下方式在RadioGroup中设置样式:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/radio_hover" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/radio_normal" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/radio_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/radio_active" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/radio_hover" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/radio_normal_off" />
<item android:state_checked="false" android:drawable="@drawable/radio_normal" />
<item android:state_checked="true" android:drawable="@drawable/radio_hover" />
</selector>将此选择器设置为您的收音机按钮。
发布于 2013-03-22 22:39:17
问题是你需要一个新的状态。按照这里的说明添加一个"state_highlighted",或者您想称之为它的任何东西:
https://stackoverflow.com/questions/4680065
复制相似问题