文本视图边框不显示



我想用我用res/drawable制作的这些行xml代码为我的TextView制作边框。但边界并没有出现。

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke android:width="4dip" android:color="#FAF9F9"/>
</shape>

这是我的activityMain.xml,其中textView是:

<TextView
android:background="@drawable/border_style"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="1. If you somehow found a way to extract all of the gold from the bubbling core of our lovely little planet, you would be able to cover all of the land in a layer of gold up to your knees."
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.96"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintVertical_bias="1.0" />

示例border_bg.xml

`

<!-- View background color -->
<solid
android:color="@color/background_color" >
</solid>
<!-- View border color and width -->
<stroke
android:width="1dp"
android:color="@color/border_color" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp"   >
</corners>

`

并将其设置为文本视图中的背景

android:background="@drawable/border_bg"

这对我有效:

<stroke
android:width="2dp"
android:color="#FFFFFF" />
<corners android:radius="20dp" />
<solid android:color="@android:color/transparent"/>

边框不显示,因为您已指定与背景颜色相同的边框颜色。给它不同的,就像下面的

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke android:width="4dip" android:color="#000000"/>
</shape>

现在将这个xml设置为文本视图的背景,如下面的

<TextView
android:background="@drawable/border_style"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="1. If you somehow found a way to extract all of the gold from the 
bubbling core of our lovely little planet, you would be able to cover all of the 
land in a layer of gold up to your knees."
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.96"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintVertical_bias="1.0" />

那是。!

尽量给边界颜色一点深,因为你的代码工作得很好,因为颜色很亮,几乎看不见,所以试着用黑色或你想要的任何颜色,即使给了深色也不起作用,请告诉我。像这个一样更改你的代码

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke android:width="4dip" android:color="#000000"/> /*change here android:color*/ 
</shape>

您无法看到边框,因为它与您的背景色混合

这样的抽屉可以"工作",让你看到

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke android:width="4dip" android:color="#FAF9F9"/>
</shape>

还可以考虑在TextView中添加一个与边框大小相同的填充(所以4dp(android:padding="4dp"

<TextView
android:background="@drawable/border_style"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:padding="4dp"
android:text="1. If you somehow found a way to extract all of the gold from the bubbling core of our lovely little planet, you would be able to cover all of the land in a layer of gold up to your knees."
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.96"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintVertical_bias="1.0" />

最新更新