Im currently working on a LoginActivity, I wanted to make an rounded Linear to put the Edittext's inside, I used an XML file to round the corners of them, but the only problem is, that they wont change their color in dark mode.
I already used the colors from the @colors file, but it wont affect at all, I tried to use cardview instead of a Linearview with an drawable file as background, but it breaks the layout.
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>
LoginActivity.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>
Maybe someone knows to fix this issue.
CodePudding user response:
To support dark mode you need separate colors.xml file for night version. To create colors file for night mode. Follow these steps. Right click on values folder New > Value Resource File In the Available Qualifiers search for Night mode and click on (>>) button. From the drop down select Night Name the file as colors
And define all the night mode colors here
Names of the colors will be same as Non-Night colors file
Another way to create colors.xml for night mode is On top left corner click on Android and Switch to project, Go to folder app > src > main > res and create a new folder and name it values-night and inside that folder create and xml file named as colors.xml