2

How create buttons with underline light when is clicked.

like tabs but i need only for buttons.

Rami
  • 7,879
  • 12
  • 36
  • 66
android java
  • 343
  • 1
  • 7
  • 13

2 Answers2

1

Checkout these tutorial.You can use TabHost

http://www.learn-android-easily.com/2013/07/android-tabwidget-example.html

http://www.androidhive.info/2011/08/android-tab-layout-tutorial/

Soham
  • 4,397
  • 11
  • 43
  • 71
0

You need to use a custom Selector (similar to Tabs Selector) as background to your 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" />

Your 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: I get this example from here.

Community
  • 1
  • 1
Rami
  • 7,879
  • 12
  • 36
  • 66