繁体   English   中英

TextView 边框不出现

[英]TextView border doesn't appear

我想用我在 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>

`

并将其设置为 textview 中的背景

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"/> /*change here android:color*/ 

</shape>

边框不出现,因为您将边框颜色设置为与背景颜色相同。 给它不同的像下面

<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/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" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM