没有出现TextView边框

时间:2018-11-19 15:26:36

标签: java android xml

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

5 个答案:

答案 0 :(得分: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"

答案 1 :(得分:0)

这对我有用:

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

答案 2 :(得分: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>

答案 3 :(得分:0)

边框不出现,因为您提供的边框颜色与背景颜色相同。像下面这样给它

for k in final_values:
    print '%s: sum is %d' % (k, sum([x for x in final_values[k] if type(x) is int]))

现在将此XML设置为文本视图的背景,如下所示

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

那个。

答案 4 :(得分: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" />