while clicking on edittext my miui/mobile theme is crashing - android

<FrameLayout 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"
android:background="#color/white"
android:padding="20dp"
tools:context=".UI.Activity.LoginActivity">
<ProgressBar
android:id="#+id/my_plan_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<RelativeLayout
android:id="#+id/login_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="#drawable/maxpe_logo" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/logo"
android:layout_marginTop="35dp"
android:text="Phone No."
android:textColor="#color/black" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/edt_phone_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Email">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edt_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Mobile No."
android:inputType="number"
android:maxLength="10"
android:paddingLeft="15dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textview.MaterialTextView
android:id="#+id/Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edt_phone_layout"
android:text="Password."
android:textColor="#color/black" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/edt_pass_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Password"
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/passtextinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"
android:paddingLeft="15dp" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/edt_pass_layout"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/button_back"
android:padding="15dp"
android:text="Log In"
android:textColor="#color/white" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/btn_login"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/forgot_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center"
android:padding="5dp"
android:text="Forget Password?"
android:textColor="#color/app_color"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
theme
<style name="Theme.EcomaxgoAttendence" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/app_color</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
i am trying this code which was running on my previous project but as soon i pasted this in my new project it is working fine with other devices only leaving few devices like redmi which is crashing when clicked on edittext
also nothing in java class
nothing in logcat
theme or mobile ui is crashing not apk does anyone have any idea

Related

BottomNavigationView not showing icons

I've checked all the other posts I can find on this and can't get the icons to even show in the Design preview but it is showing the navigation bar block in design view (with no text or icons).
I am using a nested linear layout and I have set the icons to appear as white against a darker background tint, but when I set up the action bar and tab icon type, i chose the HOLO_DARK theme so they should have been white anyway (I added the icon tint as white too, just to see if that made a difference).
Here is my xml code for the activity:
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:orientation="vertical"
tools:context=".LoginActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginBottom="25dp"
android:paddingVertical="60dp"
android:text="#string/logintext"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="40sp" />
<TextView
android:id="#+id/useremail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:text="#string/user_email"
android:textSize="20sp" />
<EditText
android:id="#+id/loginemailentryid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginBottom="30dp"
android:autofillHints=""
android:hint="#string/common_signin_button_text"
android:inputType="textEmailAddress"
android:minHeight="48dp"
tools:ignore="TextContrastCheck" />
<TextView
android:id="#+id/passwordtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:text="#string/password"
android:textSize="20sp" />
<EditText
android:id="#+id/loginpasswordentryid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginBottom="30dp"
android:autofillHints=""
android:hint="#string/prompt_password"
android:inputType="textPassword"
android:minHeight="38dp"
tools:ignore="TextContrastCheck" />
<Button
android:id="#+id/loginbuttonid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginBottom="25dp"
android:text="#string/login"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="185dp"
android:orientation="horizontal">
<TextView
android:id="#+id/registeroption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:paddingHorizontal="40dp"
android:text="#string/register"
android:textAlignment="center"
android:textSize="15sp" />
<TextView
android:id="#+id/forgotpasswordoption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="40dp"
android:text="#string/forgot_password_option"
android:textAlignment="center"
android:textColor="#color/design_default_color_primary"
android:textSize="15sp" />
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="46dp"
android:background="?android:attr/windowBackground"
android:backgroundTint="#color/design_default_color_primary"
app:itemIconTint="#fff"
app:itemTextColor="#fff"
app:labelVisibilityMode="labeled"
app:menu="#menu/navigation_menu"
app:showAsAction="ifRoom" />
</LinearLayout>
Here is my navigation menu code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/homenav"
android:title="#string/homeiconmenu"
android:enabled="true"
android:icon="#drawable/ic_home"
android:visible="true" />
<item
android:id="#+id/scoresnav"
android:title="#string/scoresiconmenu"
android:enabled="true"
android:icon="#drawable/ic_scores"
android:visible="true" />
<item
android:id="#+id/profilenav"
android:title="#string/profileiconmenu"
android:enabled="true"
android:icon="#drawable/ic_account"
android:visible="true" />
</menu>
Some of the posts I have already checked and tried:
Android BottomNavigationView not shows
Bottom Navigation Bar not showing icons or text
Why my Bottom Navigation View does not show any titles or icons?
BottomNavigationView not show icon

Why is my dynamic theme not being displayed properly?

I have two themes: the Default one (green) and a red variation.
I set my theme dynamically on the MainActivity, but it looks like a weird mix of both themes.
For some reason only some items change to the new theme and some remain like the old one.
Image
Both, the red and green parts have the tint set to the color accent:
HomeFragment.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:id="#+id/homeConstraint"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.HomeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/homeToolsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/homeSortButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_sort_32"
android:tint="?attr/colorAccent" />
<ImageButton
android:id="#+id/homeCancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_close_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<LinearLayout
android:id="#+id/homeSelectionTools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<ImageButton
android:id="#+id/homeColorAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_color_lens_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<ImageButton
android:id="#+id/homeTagAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_label_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<ImageButton
android:id="#+id/homedeleteAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_delete_forever_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<ImageButton
android:id="#+id/homeSelectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_done_32"
android:tint="?attr/colorAccent" />
</LinearLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/homeRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/homeEmptyLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/homeEmptyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="15dp"
android:contentDescription="Tip"
android:src="#drawable/ic_baseline_inbox_120"
app:tint="?attr/colorAccent" />
<TextView
android:id="#+id/homeEmptyTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_sans_extrabold"
android:text="What an empty place..."
android:textAlignment="center"
android:textSize="24sp" />
<TextView
android:id="#+id/homeEmptyDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_sans_bold"
android:text="There are no notes. Try creating a new one"
android:textAlignment="center"
android:textSize="20sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Home Activity
<?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:id="#+id/homeConstraint"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.HomeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/homeToolsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/homeSortButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_sort_32"
android:tint="?attr/colorAccent" />
<ImageButton
android:id="#+id/homeCancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_close_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<LinearLayout
android:id="#+id/homeSelectionTools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<ImageButton
android:id="#+id/homeColorAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_color_lens_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<ImageButton
android:id="#+id/homeTagAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_label_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<ImageButton
android:id="#+id/homedeleteAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_delete_forever_32"
android:tint="?attr/colorAccent"
android:visibility="gone" />
<ImageButton
android:id="#+id/homeSelectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_round_done_32"
android:tint="?attr/colorAccent" />
</LinearLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/homeRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/homeEmptyLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/homeEmptyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="15dp"
android:contentDescription="Tip"
android:src="#drawable/ic_baseline_inbox_120"
app:tint="?attr/colorAccent" />
<TextView
android:id="#+id/homeEmptyTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_sans_extrabold"
android:text="What an empty place..."
android:textAlignment="center"
android:textSize="24sp" />
<TextView
android:id="#+id/homeEmptyDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_sans_bold"
android:text="There are no notes. Try creating a new one"
android:textAlignment="center"
android:textSize="20sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
As you can see, homeSortButton from the HomeFragment is red, and newFAB from the MainActivity is green, but both have the same value.
This is my themes.xml file:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="android:windowBackground">#color/white</item>
<item name="colorAccent">#color/green</item>
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryVariant">#color/green</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/green</item>
<item name="colorSecondaryVariant">#color/green</item>
<item name="colorOnSecondary">#color/white</item>
<item name="android:overScrollMode">never</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.MyApp.Red" parent="Theme.MyApp">
<item name="android:windowBackground">#color/white</item>
<item name="colorAccent">#color/red</item>
<item name="colorPrimary">#color/red</item>
<item name="colorPrimaryVariant">#color/red</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/red</item>
<item name="colorSecondaryVariant">#color/red</item>
<item name="colorOnSecondary">#color/white</item>
<item name="android:overScrollMode">never</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
</style>
To set the theme, I call this in OnViewCreated() from my Settings Fragment:
appColorSpinner.onItemSelectedListener = object: AdapterView.OnItemSelectedListener{
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
var themeColor: Int = 0
when(position){
0 -> {
themeColor = GREEN_COLOR
mContext?.setTheme(R.style.Theme_MyApp)
}
1 -> {
themeColor = RED_COLOR
mContext?.setTheme(R.style.Theme_MyApp_Blue)
}
}
pref?.edit()?.putInt("colorTheme", themeColor)?.apply()
}
I call this in OnCreate from my MainActivity to load the theme:
fun setCurrentTheme(){
val prefs = getSharedPreferences("preferences", Context.MODE_PRIVATE)
val color = prefs.getInt("colorTheme", GREEN_COLOR)
when(color){
GREEN_COLOR -> {
setTheme(R.style.Theme_ZenNotes)
}
RED_COLOR -> {
theme.applyStyle(R.style.Theme_ZenNotes_Red, true)
}
BLUE_COLOR -> {
setTheme(R.style.Theme_ZenNotes_Blue)
}
YELLOW_COLOR -> {
setTheme(R.style.Theme_ZenNotes_Yellow)
}
PURPLE_COLOR -> {
setTheme(R.style.Theme_ZenNotes_Purple)
}
}
}
What could be causing this weird behavior?
Ok, so noob mistake. I had to call setCurrentTheme() before setContentView(...) on my Activity.

Android - Scale Image to status bar of the phone

Simply, I have a linear layout that separates the screen to 2 pieces from middle and in the first piece I have a constraint layout that contains mountain.png .Because of i set NoActionBar and white for statusBarColor in Themes.xml, as a result above the image there is area that seems white.So I want to remove the white area and scale the image through status bar of the phone.
I tried to remove status bar, it didn't work.
I tried to add android:fitsSystemWindows="true" attribute to .XML file and it didn't work too.
My .xml file
<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=".ui.sign_in.telephone.PhoneNumberFragment"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#drawable/mountain">
<TextView
android:id="#+id/baslaText"
android:layout_width="match_parent"
android:gravity="center"
android:layout_marginTop="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:layout_height="wrap_content"
android:textSize="38sp"
android:textColor="#color/white"
android:text="Başlayın" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/baslaText"
android:layout_marginTop="20dp"
android:textColor="#color/white"
android:textSize="16sp"
android:text="Taşımaya başlamak için kaydolun, ilk \n olarak telefon numaranızı girin"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
android:elevation="4dp"
app:cardCornerRadius="14dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/telephoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Telefon numaranızı giriniz"
android:textColor="#color/black"
android:textSize="28sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="match_parent"
android:gravity="center"
android:id="#+id/telephoneText"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:textSize="18sp"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneNumber"
android:text="Taşımaya başlamak için kaydolun, ilk \n olarak telefon numaranızı girin"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/telephoneTag"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="40dp"
android:text="Telefon Numarası"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneText" />
<com.google.android.material.textfield.TextInputLayout
android:elevation="2dp"
app:cardCornerRadius="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/telephoneNumberInput"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneTag"
android:layout_marginTop="20dp"
app:errorEnabled="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/telephoneNumberEditText"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:inputType="number"
android:hint="+.. ... ... .. .."
android:maxLength="12"
android:textColor="#color/black"
android:textSize="14sp"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="30dp"
android:layout_marginBottom="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:background="#color/purple_500"
android:backgroundTint="#color/purple_500"
android:text="Başlayın"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneNumberInput" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
My themes.xml file.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.UI" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/teal_200</item>
<item name="colorPrimaryVariant">#color/white</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
write this on your activity onCreate:
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().setStatusBarColor(Color.TRANSPARENT);
This code piece did the job I desired.

How to style DatePicker on Android

I have date picker which I've tried to customize to a different style but to no avail.
I want to show a DatePicker and not a DatePickerDialog.
In the layout design tab on Android Studio, the DatePicker's background color is black and the text color is white.
However, the datePicker occupies space on the device screen but is not visible.
I've also tried to change the AppTheme.
The DatePicker code is below:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.AgeFragment">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/roboto_medium"
android:text="Sign up"
android:textColor="#color/titleBlack"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
app:srcCompat="#drawable/ic_baseline_arrow_back_24"
app:layout_constraintBottom_toBottomOf="#+id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/textView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:fontFamily="#font/roboto_medium"
android:text="When's your birthday?"
android:textColor="#color/titleBlack"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-condensed"
android:text="Your birthday won't be shown publicly"
android:textColor="#7A7474"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<DatePicker
android:id="#+id/date_picker2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:calendarViewShown="false"
android:calendarTextColor="#android:color/holo_green_dark"
android:background="#android:color/holo_red_dark"
android:datePickerMode="spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3"
tools:targetApi="lollipop" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="#color/pinkBtnBackground"
android:fontFamily="sans-serif-medium"
android:text="Next"
android:textAllCaps="false"
android:textColor="#android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/date_picker2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
<item name="colorAccent">#android:color/transparent</item>
<item name="android:background">#android:color/white</item>
<item name="android:textColor">#color/textColor</item>
<item name="android:datePickerStyle">#style/DatePickerStyle</item>
</style>
<style name="DatePickerStyle">
<item name="android:calendarTextColor" tools:ignore="NewApi">#android:color/holo_green_dark</item>
<item name="backgroundColor">#android:color/holo_red_dark</item>
</style>
The result is still the same. I've searched for answers but none provides a solution to this problem.
Any help or reference to a documentation that provide an explanation would be highly appreciated.
Try removing <item name="android:background">#android:color/white</item> from the style. It is messing with your current Layout

Android EditText error message popup text not showing

I'm having an issue in my app where the error popup on EditTexts shows but the text is not visible.
It looks something like this:
This happens with all the EditTexts in my app.
Here's an example layout XML
Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:fitsSystemWindows="true"
tools:context=".ui.onboarding.profile.OnboardingUserProfileActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
app:srcCompat="#drawable/shapes_background" />
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="80dp"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:layout_marginBottom="20dp">
<ImageView
android:id="#+id/profileImageView"
android:layout_width="160dp"
android:layout_height="160dp"
android:scaleType="fitXY"
android:src="#drawable/user_profile_placeholder"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/cameraImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#android:drawable/ic_menu_camera" />
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/firstnameTvLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="0.33"
android:textColorHint="#color/colorVeryLightGray"
android:theme="#style/AppTheme.WhiteColorAccent"
app:errorTextAppearance="#style/error_appearance">
<android.support.design.widget.TextInputEditText
android:id="#+id/firstnameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_firstname"
android:inputType="textPersonName"
android:maxLines="1"
android:nextFocusDown="#id/lastnameTv"
android:nextFocusForward="#id/lastnameTv"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHint="#color/colorWhite"
android:theme="#style/AppTheme.WhiteEditText"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/lastnameTvLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="0.33"
android:textColorHint="#color/colorVeryLightGray"
android:theme="#style/AppTheme.WhiteColorAccent">
<android.support.design.widget.TextInputEditText
android:id="#+id/lastnameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_lastname"
android:inputType="textPersonName"
android:maxLines="1"
android:nextFocusDown="#id/usernameTv"
android:nextFocusForward="#id/usernameTv"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHint="#color/colorWhite"
android:theme="#style/AppTheme.WhiteEditText" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/usernameTvLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.33"
android:textColorHint="#color/colorVeryLightGray"
android:theme="#style/AppTheme.WhiteColorAccent">
<android.support.design.widget.TextInputEditText
android:id="#+id/usernameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_username"
android:imeActionId="6"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:maxLines="1"
android:nextFocusDown="#id/nextBtn"
android:nextFocusForward="#id/nextBtn"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHint="#color/colorWhite"
android:theme="#style/AppTheme.WhiteEditText" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/nextBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="16dp"
android:text="#string/next"
android:textStyle="bold"
android:theme="#style/AppTheme.PrimaryButton"
app:layout_anchor="#+id/form"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
And the styles:
<style name="AppTheme.WhiteColorAccent">
<item name="colorAccent">#color/colorWhite</item>
</style>
<style name="AppTheme.WhiteEditText" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#color/colorWhite</item>
<item name="colorControlNormal">#color/colorVeryLightGray</item>
<item name="colorControlActivated">#color/colorWhite</item>
<item name="colorControlHighlight">#color/colorWhite</item>
</style>
Setting error in the activity using firstnameTv.error = "This field can not be empty" (Kotlin)
You need to use
style="#style/AppTheme.WhiteEditText"
Instead of android:theme="#style/AppTheme.WhiteColorAccent"
Now question is why need to use style Instead of android:theme
When you use style it apply will apply only to that view
and When you use android:theme it apply will apply view as well as all of its children.
Read more about What is the difference between style and android:theme attributes?
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="#+id/main_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:background="#color/colorPrimary">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:visibility="gone" />
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:fillViewport="true">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="80dp"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:layout_marginBottom="20dp">
<ImageView
android:id="#+id/profileImageView"
android:layout_width="160dp"
android:layout_height="160dp"
android:scaleType="fitXY"
android:src="#color/colorNavBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/cameraImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#android:drawable/ic_menu_camera" />
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/firstnameTvLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="0.33"
android:textColorHint="#color/colorVeryLightGray"
style="#style/AppTheme.WhiteColorAccent"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/firstnameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:inputType="textPersonName"
android:maxLines="1"
android:imeOptions="actionNext"
android:nextFocusDown="#id/lastnameTv"
android:nextFocusForward="#id/lastnameTv"
android:textColor="#android:color/white"
android:textColorHint="#color/colorWhite"
style="#style/AppTheme.WhiteEditText" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/lastnameTvLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="0.33"
android:textColorHint="#color/colorVeryLightGray"
style="#style/AppTheme.WhiteColorAccent">
<android.support.design.widget.TextInputEditText
android:id="#+id/lastnameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"
android:inputType="textPersonName"
android:maxLines="1"
android:nextFocusDown="#id/usernameTv"
android:nextFocusForward="#id/usernameTv"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHint="#color/colorWhite"
style="#style/AppTheme.WhiteEditText" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/usernameTvLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="0.33"
android:textColorHint="#color/colorVeryLightGray"
style="#style/AppTheme.WhiteColorAccent">
<android.support.design.widget.TextInputEditText
android:id="#+id/usernameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="user Name"
android:imeActionId="6"
android:imeActionLabel="AB"
android:imeOptions="actionUnspecified"
android:maxLines="1"
android:nextFocusDown="#id/nextBtn"
android:nextFocusForward="#id/nextBtn"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHint="#color/colorWhite"
style="#style/AppTheme.WhiteEditText" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/nextBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="16dp"
android:text="Next"
android:textStyle="bold"
app:layout_anchor="#+id/form"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
style
<style name="AppTheme.WhiteColorAccent">
<item name="colorAccent">#color/colorWhite</item>
</style>
<style name="AppTheme.WhiteEditText" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#color/colorWhite</item>
<item name="colorControlNormal">#color/colorVeryLightGray</item>
<item name="colorControlActivated">#color/colorWhite</item>
<item name="colorControlHighlight">#color/colorWhite</item>
</style>
OUTPUT
You need to set the error in TextInputLayout, NOT in TextInputEditText
firstnameTvLayout.setError("Error goes here");
Also make sure you have done
firstnameTvLayout.setErrorEnabled(true);
See the documentation here for more details https://developer.android.com/reference/android/support/design/widget/TextInputLayout
You have to use style instead of android:theme. If you set android:theme to a view group, its children (error pop-up, in this case) will use the same style.
Your code
<android.support.design.widget.TextInputLayout
....
android:theme="#style/AppTheme.WhiteColorAccent"
....>
Change it to
<android.support.design.widget.TextInputLayout
....
style="#style/AppTheme.WhiteColorAccent"
....>
textInputLayout.setErrorEnable(true);

Categories

Resources