Как я могу заставить текст TextView использовать стиль, который я ему даю? - PullRequest
0 голосов
/ 09 июля 2019

В Android на TextView, как я могу сделать текст ▶ Play, используя стиль, который я ему даю. Проблема с текстом . На эмуляторе он отображается нормально, однако при тестировании на устройстве он выглядит синим с белым текстом.

Следующий код:

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="▶ Play"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Производит:

Screenshot

И

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_light"
        android:textColor="@android:color/black"
        android:text="▶ Play"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Производит:

enter image description here

Ответы [ 2 ]

0 голосов
/ 09 июля 2019
You can drawableStart to set an icon before text in Textview
<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawableStart="@drawable/play_button_icon"
    android:text="Play"/>

 To download icon use : https://materialdesignicons.com/
0 голосов
/ 09 июля 2019

вот решение для вас ... Просто используйте android:drawableLeft="@drawable/your_icon" в вашем текстовом просмотре.

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_light"
        android:textColor="@android:color/black"
        android:drawableLeft="@drawable/your_icon"
        android:text="Play"/>

</androidx.constraintlayout.widget.ConstraintLayout>
...