簡體   English   中英

如何使 TextView 的顏色像這張圖片?

[英]How to make the color of a TextView like this image?

我想設置像這個圖像這樣的文本視圖的顏色,它有一條垂直的紅色線,整個文本視圖就像粉紅色或微紅色。

在此處輸入圖像描述

您可以使用水平方向的線性布局並在其中放置一個視圖。

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FirstFragment">

    <LinearLayout
        android:background="@color/teal_200"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@id/button_first"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <View
            android:layout_width="5dp"
            android:background="@color/cardview_dark_background"
            android:layout_height="match_parent"/>
        <TextView
            android:id="@+id/textview_first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingStart="5dp"
            android:text="@string/hello_first_fragment"
            android:background="@drawable/side_line"
             />

    </LinearLayout>


    <Button
        android:id="@+id/button_first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textview_first" /></androidx.constraintlayout.widget.ConstraintLayout>

只需更改顏色,您就可以開始了。 輸出看起來像這樣...... 在此處輸入圖像描述

您可以使用圖層列表。 不需要更多的觀點

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:shape="rectangle">
            <solid android:color="@color/teal_700"/>
        </shape>
    </item>

    <item android:start="5dp">
        <shape
            android:shape="rectangle">
            <solid android:color="@color/teal_200"/>
        </shape>
    </item>
</layer-list>

在你的 TextView

android:background="@drawable/your_layer_list"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM