我目前正在研究 LoginActivity,我想制作一個圓角的 Linear 來放置 Edittext 的內部,我使用了一個 XML 檔案來圓角它們的角,但唯一的問題是,它們在暗模式下不會改變顏色。
我已經使用了@colors 檔案中的顏色,但它根本不會影響,我嘗試使用 cardview 而不是帶有可繪制檔案作為背景的 Linearview,但它破壞了布局。
XML:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/design_default_color_on_primary"/>
<stroke android:width="0dp" android:color="#B1BCBE" />
<corners android:radius="20dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
登錄活動.xml:
<?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=".LoginActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/login_bg1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="@ id/linearLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/loginbg"
android:elevation="25dp"
android:orientation="vertical"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginVertical="20dp"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="@color/design_default_color_primary"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="44dp"
android:layout_marginStart="44dp"
android:padding="10dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@drawable/edittext_box"
android:elevation="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_email"/>
<EditText
android:id="@ id/Email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@null"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColorHint="@color/design_default_color_primary"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="44dp"
android:layout_marginStart="44dp"
android:padding="10dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@drawable/edittext_box"
android:elevation="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_password"/>
<EditText
android:id="@ id/Password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@null"
android:hint="Password"
android:inputType="textPassword"
android:textColorHint="@color/design_default_color_primary"/>
</LinearLayout>
<Button
android:id="@ id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Login"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
也許有人知道解決這個問題。
uj5u.com熱心網友回復:
要支持暗模式,您需要一個單獨的用于夜間版本的 colors.xml 檔案。為夜間模式創建顏色檔案。按著這些次序。右鍵單擊 values 檔案夾 New > Value Resource File 在 Available Qualifiers 中搜索 Night mode 并單擊 (>>) 按鈕。從下拉串列中選擇 Night 將檔案命名為顏色
并在此處定義所有夜間模式顏色
顏色名稱將與非夜間顏色檔案相同
為夜間模式創建colors.xml的另一種方法是在左上角單擊Android并切換到專案,轉到檔案夾app> src> main> res并創建一個新檔案夾并將其命名為values-night并在該檔案夾內創建一個名為 colors.xml 的 XML 檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/316706.html
標籤:安卓 xml 安卓工作室 安卓布局 android-dark-主题
