设置Android按钮的状态
我声明Android按钮如下:设置Android按钮的状态,android,button,state,Android,Button,State,我声明Android按钮如下: <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/festival_button_selector" android:textColor="@color/white" android:text="@string/STR_FEST_SELOFF" android:onClick="
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/festival_button_selector"
android:textColor="@color/white"
android:text="@string/STR_FEST_SELOFF"
android:onClick="onBtnFestSelectionClick"
/>
以下是此按钮选择器背景的内容(节日按钮选择器):
实际上,我想将这个按钮背景设置为默认的“焦点”状态(所以按钮背景将是festival\u button\u focus)。如果单击其他按钮,此按钮背景将返回“正常”状态(背景为festival_按钮)。我们能做到吗
我不想改变节日按钮选择器。如果我们有一个像button.setFocusState(true)这样的函数,这将是理想的选择。将此按钮设置为焦点状态。听起来您需要调用按钮。查看设置初始焦点状态。
<item android:state_focused="true"
android:drawable="@drawable/festival_button_focus"
/>
<item android:state_pressed="true"
android:drawable="@drawable/festival_button_press"
/>
<item
android:drawable="@drawable/festival_button"
/>
试试这个requestFocus()看起来不错,但不幸的是,这个方法在Android 2.1和2.2中有缺陷:。无论如何,感谢您的回复。从您的链接来看,解决方案似乎是使用runnable设置焦点。新线程(new runnable(){public void run(){((按钮)findViewById(R.id.btnFestivalSelection)).requestFocus();}});//->这对我不起作用。
<item android:state_focused="true"
android:drawable="@drawable/festival_button_focus"
/>
<item android:state_pressed="true"
android:drawable="@drawable/festival_button_press"
/>
<item
android:drawable="@drawable/festival_button"
/>