添加指标到按钮背景

时间:2015-04-27 05:28:22

标签: java android xml button drawable

我想在我的按钮上添加一个指示器。 与此类似:Image

我该怎么办?我能够打造坚实的背景,但我不知道如何添加小蓝块部分。任何帮助表示赞赏。

由于

2 个答案:

答案 0 :(得分:1)

在xml文件中添加此radiobutton

<RadioButton
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/home_selector"
android:button="@android:color/transparent"
android:checked="true" />

<RadioButton
    android:id="@+id/favourite"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/fav_selector"
    android:button="@android:color/transparent"
    android:checked="true" />
....

现在您可以根据需要为每个不同的单选按钮创建一个选择器

home_selector.xml

<item
    android:drawable="@drawable/home_selected"
    android:state_checked="true" />
<item
    android:drawable="@drawable/home_normal" />

fav_selector.xml

<item
    android:drawable="@drawable/fav_selected"
    android:state_checked="true" />
<item
    android:drawable="@drawable/fav_normal" />

像这样你可以为你想要的单选按钮创建选择器

答案 1 :(得分:-2)

你可以这样做 通过在按钮上方添加颜色的视图

 <LinearLayout
        android:layout_width="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:layout_height="wrap_content">

        <View
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:visibility="visible"
            android:background="#000000" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher" />
    </LinearLayout>

在其点击

上设置其可见性
相关问题