[英]Border with title in Android?
We can use shape
to create a simple border,for example I saw this code here : 我们可以使用
shape
创建一个简单的边框,例如,我在这里看到了以下代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dip" />
<solid android:color="@color/black" />
<stroke android:width="2dip" android:color="@color/white" />
</shape>
</item>
</layer-list>
But I need a border with a title like this image: 但是我需要一个标题如下图的边框:
How I can do that? 我该怎么做?
Try out the below code and create the xml file in your application's res/drawable
folder and paste the below code: 试用以下代码,并在应用程序的
res/drawable
文件夹中创建xml文件,然后粘贴以下代码:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="3dp" /> <solid android:color="#00000000" /> <stroke android:width="2dp" android:color="#1B455F" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp"/> </shape>
You can change the border color according to your convenience by changing the stroke color. 您可以根据需要通过更改笔触颜色来更改边框颜色。
Use the above xml as below: Here i have tried to set the border on the TextView. 使用上面的xml,如下所示:在这里,我尝试在TextView上设置边框。
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/border" android:text="@string/hello_world" />
I hope it will help you. 希望对您有帮助。
Thanks. 谢谢。
Now I found a good code that helps me here .I add code here: 现在,我找到了一个很好的代码来帮助我。 在这里添加代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:color="#000000">
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/rectangle"
android:layout_margin="20dp"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#000000"
android:layout_marginTop="10dp"
android:text="TITLE!"
android:textColor="#ffffff"/>
</RelativeLayout>
And @drawable/rectangle is in a drawable rectangle.xml file like this: @ drawable / rectangle在这样的可绘制的angle.xml文件中:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<stroke android:width="2dip" android:color="#ffffff"/>
</shape>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.