首页 > 解决方案 > 如何制作主题?

问题描述

我有一个列表项,因为我有某些文本视图和图像视图。问题是我得到的设计有深色、棕色和浅色三个主题。现在,如果我想将列表项的背景更改为这三种颜色中的任何一种,我该如何设置背景。就像我从设置中更改应用程序的主题一样,列表项背景应该会更改。我应该如何制作具有不同背景的主题?

<LinearLayout 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="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="12dp"
        android:paddingEnd="16dp"
        android:paddingStart="16dp"
        android:paddingTop="12dp">

        <TextView
            android:id="@+id/company_name_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/montserratlight"
            android:text="Synergy Bizcon"
            android:textColor="@color/textColorMediumThemeDark"
            android:textSize="@dimen/fontMedium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/schedule_imageview"
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:layout_marginTop="5dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/company_name_textview"
            app:srcCompat="@drawable/ic_watch" />

        <TextView
            android:id="@+id/date_time_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="6dp"
            android:layout_marginTop="4dp"
            android:fontFamily="@font/montserratlight"
            android:text="26 Apr 11:10 PM"
            android:textColor="@color/textColorSmallThemeDark"
            android:textSize="@dimen/fontExtraSmall"
            app:layout_constraintStart_toEndOf="@id/schedule_imageview"
            app:layout_constraintTop_toBottomOf="@id/company_name_textview" />

        <TextView
            android:id="@+id/pipe_textview"
            android:layout_width="0.5dp"
            android:layout_height="12dp"
            android:layout_marginStart="6dp"
            android:background="@color/textColorSmallThemeDark"
            app:layout_constraintBottom_toBottomOf="@id/date_time_textview"
            app:layout_constraintStart_toEndOf="@id/date_time_textview"
            app:layout_constraintTop_toTopOf="@id/date_time_textview" />

        <TextView
            android:id="@+id/exhcange_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="6dp"
            android:fontFamily="@font/montserratlight"
            android:text="BSE"
            android:textColor="@color/textColorSmallThemeDark"
            android:textSize="@dimen/fontExtraSmall"
            app:layout_constraintBottom_toBottomOf="@id/pipe_textview"
            app:layout_constraintStart_toEndOf="@id/pipe_textview"
            app:layout_constraintTop_toTopOf="@id/pipe_textview" />

        <TextView
            android:id="@+id/rate_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:fontFamily="@font/montserratlight"
            android:text="34567.58"
            android:textColor="@color/textColorMediumThemeDark"
            android:textSize="@dimen/fontMedium"
            app:layout_constraintEnd_toStartOf="@id/add_imageview"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/points_change_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:fontFamily="@font/montserratlight"
            android:text="-21.10(-0.02%)"
            android:textColor="@color/textColorSmallThemeDark"
            android:textSize="@dimen/fontExtraSmall"
            app:layout_constraintEnd_toEndOf="@id/rate_textview"
            app:layout_constraintTop_toBottomOf="@id/rate_textview" />

        <ImageView
            android:id="@+id/add_imageview"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:tint="@color/iconsColor"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_add" />

    </android.support.constraint.ConstraintLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:background="@color/listItemDivider" />

</Linear Layout>

就像我有这个列表项一样,我想将约束布局背景更改为深色或棕色或浅色。我最终会使用样式来提供背景,但我不知道如何?有人可以帮忙吗?谢谢

标签: androiduser-interfacestylesthemes

解决方案


推荐阅读