Far*_*tel 2 xml android button
我为我的布局制作了一个自定义按钮,但问题是它没有显示我的onclick效果.这里是我的三个xml文件,我已经建立了我给按钮椭圆形状你还可以告诉我如何使按钮成为一个圆形,尺寸更小?thnx提前
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:gravity="center"
android:textSize="25sp" />
<Spinner
android:id="@+id/spin"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:text="heyyy"
android:layout_below="@+id/textView1"
/>
<Button
android:layout_marginTop="20dp"
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="150sp"
android:text="add"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/spin"
android:background="@drawable/button_xml"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/button1"
android:gravity="left"
android:textSize="25sp"
android:text="add" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:gravity="right"
android:textSize="25sp"
android:text="a" />
<Button
android:layout_marginTop="20dp"
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="50sp"
android:text="reset"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/textView3"/>
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
button_xml.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<solid
android:color="#03A89E"/>
<stroke android:width="2dp"
android:color="#ffffff"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
button_click.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="@drawable/button_xml"
/>
</selector>
Run Code Online (Sandbox Code Playgroud)
Pra*_* シ 7
这是按钮选择器的完整XML代码
button_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/button_light_green"/>
<corners android:radius="5dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
button_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/button_light_green_selected"/>
<corners android:radius="5dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/button_selected"/>
<item android:state_focused="true" android:drawable="@drawable/button_selected"/>
<item android:drawable="@drawable/button_normal"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
最后将其添加到您的按钮背景中......
<Button
android:layout_marginTop="20dp"
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="150sp"
android:text="add"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/spin"
android:background="@drawable/button_bg"/> <!-- Add Selector File here to have click effect -->
Run Code Online (Sandbox Code Playgroud)