我正在尝试创建一个应用程序并在我的应用程序中我尝试在按钮底部创建边框,但是当我运行应用程序时它只显示顶部的边框,任何人都可以告诉如何实现这一点。以下是我的xml UI?.........
<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>
Myjava.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);
}
});
答案 0 :(得分:5)
你的问题有所不同,或者你无法解释,但我得到了它
Bottom_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" />
最终视图
答案 1 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#FFFFFF"
android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#eecc68" />
</shape>
答案 2 :(得分:0)
代码 -
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--Minus (-) how much dp you gave in the stroke width from left right top-->
<item android:left="-10dp" android:right="-10dp" android:top="-10dp">
<shape
android:shape="rectangle">
<stroke
android:width="10dp"
android:color="@android:color/holo_red_dark" />
<!--This is the main background -->
<solid android:color="#FFDDDDDD" />
</shape>
</item>
</layer-list>
预览 -