我有一个线性布局,有一些自动完成和文本框。我想在线性布局中插入一个形状(矩形)。我怎样才能做到这一点。我是安卓新手。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="@+id/layout">
<AutoCompleteTextView android:id="@+id/autocompleteCountry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/CONTRY_LABEL"
/>
<AutoCompleteTextView android:id="@+id/locationAutoCompleteFrom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/from"
android:visibility="gone"
/>
<AutoCompleteTextView android:id="@+id/locationAutoCompleteTO"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/to"
android:visibility="gone"
/>
<!-- <Button android:id="@+id/buttonRoute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonRouteText"
android:enabled="false"
android:clickable="true"
/>
-->
您应该使用 ShapeDrawable 作为要添加样式的组件的背景。
可绘制的形状是在 XML 中使用以下语法创建的(这个显示了一个带有圆角的矩形,但是您可以执行很多操作来自定义它以使其看起来像您想要的那样)。这个文件(名为background_square.xml或其他)应该放在你的drawable文件夹中:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<solid
android:color="@color/primary_grey" />
</shape>
然后,当您想将其添加到视图中时,可以在 XML 中使用以下语法:
android:background="@drawable/background_square"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)