我正在尝试创建一个应用程序,在我的应用程序中,我试图在按钮的底部创建边框,但是当我运行应用程序时,它只在顶部显示边框,有人能告诉我如何实现这个吗..以下是我的 xml用户界面?…………
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:context="com.example.button_pressed_effect_example.MainActivity" >
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="One"
android:id="@+id/button1"
android:background="@drawable/custom_btn_black_orange"
android:drawableBottom="@drawable/liti"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Two"
android:id="@+id/button2"
android:background="@drawable/custom_btn_black_orange"
/>
</LinearLayout>
liti.xml
<layer-list /android">
<item android:left="10dp" android:bottom="10dp">
<shape android:shape="line">
<stroke android:width="10dp" android:color="#ffffff" />
</shape>
</item>
</layer-list>
custom_btn_black_orange.xml
<selector >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<gradient
android:angle="-90"
android:startColor="#5B0B0E"
android:endColor="#5B0B0E" />
</shape>
</item>
<item android:state_pressed="false">
<shape android:shape="rectangle" >
<solid android:color="#731013"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<gradient
android:angle="-90"
android:startColor="#5B0B0E"
android:endColor="#5B0B0E" />
</shape>
</item>
</selector>
custom_btn_black_orangepressed.xml
<selector>
<item android:state_pressed="false" >
<shape android:shape="rectangle" >
<gradient
android:angle="-90"
android:startColor="#5B0B0E"
android:endColor="#5B0B0E" />
</shape>
</item>
<item android:state_pressed="false">
<shape android:shape="rectangle" >
<solid android:color="#731013"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<gradient
android:angle="-90"
android:startColor="#5B0B0E"
android:endColor="#5B0B0E" />
</shape>
</item>
</selector>
我的java.java
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
btn.setBackgroundResource(R.drawable.custom_btn_black_orangepressed);
btn2.setBackgroundResource(R.drawable.custom_btn_black_orange);
}
});
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
btn2.setBackgroundResource(R.drawable.custom_btn_black_orangepressed);
btn.setBackgroundResource(R.drawable.custom_btn_black_orange);
}
});
你的问题不一样或者你无法解释,但是我明白了
- 在drawable中创建两个文件bottom_selected和bottom_unselected
底部_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#001EFF" />
</shape>
</item>
<item android:bottom="3dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
Bottom_unselected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#001EFF" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
现在你的按钮
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/fragment_container"
android:layout_marginLeft="54dp"
android:layout_marginTop="110dp"
android:background="@drawable/bottom_selected"
android:text="Button" />
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:background="@drawable/bottom_unselected"
android:text="Button" />
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/Button01"
android:layout_alignBottom="@+id/Button01"
android:layout_toRightOf="@+id/Button01"
android:background="@drawable/bottom_unselected"
android:text="Button" />
最终 View
我是一名优秀的程序员,十分优秀!