点击时如何创建带下划线灯的按钮。
喜欢标签,但我只需要按钮。
答案 0 :(得分:1)
查看这些教程。您可以使用TabHost
http://www.learn-android-easily.com/2013/07/android-tabwidget-example.html
http://www.androidhive.info/2011/08/android-tab-layout-tutorial/
答案 1 :(得分:0)
您需要使用自定义Selector
(类似于Tabs
选择器)作为Button
的背景。
<Button
android:id="@+id/button"
android:background="@drawable/button_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My button" />
您的button_background.xml
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_holo" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_holo" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />
</selector>
PS:我从here得到了这个例子。