Want to change the focused hint Edittext colour but it is not changing. What's the matter ? Have used all the attributes in the edit Text theme but yet it's not changing.I have changed the parent theme from MaterialComponents to App Compat , is it becoz of that ?
This is my themes.xml file.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.QuizApp" parent="Theme.AppCompat.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>
<!-- 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:windowFullscreen">true</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="fontFamily">#font/font10</item>
</style>
<style name="heading_name" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="fontFamily">#font/font1</item>
<item name="textFillColor">#2B0031</item>
</style>
<style name="EditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/purple_gray</item>
<item name="colorControlActivated">#color/purple_gray</item>
<item name="colorControlHighlight">#color/purple_gray</item>
<item name="hintTextColor">#color/purple_gray</item>
<item name="android:textColorHint">#color/purple_gray</item>
<item name="boxStrokeErrorColor">#color/purple_gray</item>
</style>
<style name="Theme.QuizApp.NoActionBarAndStatusBar" >
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="fontFamily">#font/font10</item>
</style>
<style name="progressBarBlue" parent="#style/Theme.AppCompat">
<item name="colorAccent">#4568dc</item>
</style>
<style name="Theme.QuizApp.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.QuizApp.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
This is the activity_main.xml file.
<?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"
android:id="#+id/main_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/screen_background"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<TextView
style="#style/heading_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:fontFamily="#font/font1"
android:gravity="center"
android:shadowColor="#450750"
android:shadowDx="1.5"
android:shadowDy="1.5"
android:shadowRadius="1.6"
android:text="Quiz App !"
android:textColor="#color/white"
android:textColorHighlight="#8F22A1"
android:textColorHint="#7F1491"
android:textSize="55sp"
android:textStyle="bold" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
app:cardElevation="50dp"
app:cardMaxElevation="100dp"
app:cardUseCompatPadding="false"
android:layout_marginEnd="20dp"
app:cardCornerRadius="12dp"
android:background="#color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/font3"
android:gravity="center_horizontal"
android:text="Welcome ! "
android:textColor="#000000"
android:textSize="40sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please Enter Your Name "
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center_horizontal"
android:layout_marginTop="16dp"
android:textColor="#color/black"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.Material3.TextInputEditText.OutlinedBox"
android:layout_marginTop="20dp">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
tools:text="Nandini"
android:textCursorDrawable="#drawable/cursor"
android:inputType="textCapWords"
android:textColor="#000000"
android:shadowColor="#color/purple_gray"
android:theme="#style/EditTextTheme"
android:textColorHighlight="#color/purple_gray"
android:textColorLink="#color/purple_gray"
android:backgroundTint="#color/purple_gray"
app:hintTextColor="#color/purple_gray"
android:outlineAmbientShadowColor="#color/purple_gray"
android:textColorHint="#color/purple_gray"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/btn_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Start Quiz"
android:textStyle="bold"
android:elevation="100dp"
android:stateListAnimator="#null"
android:layout_gravity="center_horizontal"
android:background="#drawable/button_bg"
android:textColor="#color/white"
android:textSize="20sp"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
This is MainActivity.kt file.
package com.nandini.android.quizapp
import android.content.Intent
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btn_start : Button =findViewById(R.id.btn_start)
val et_name : EditText=findViewById(R.id.et_name)
btn_start.setOnClickListener {
if(et_name.text.isEmpty())
{
et_name.setError("")
Toast.makeText(this, "Enter name",Toast.LENGTH_LONG).show()
}else{
val intent = Intent(this,QuizQuestionActivity::class.java)
intent.putExtra(Constants.USER_NAME,et_name.text.toString())
startActivity(intent)
}
}
}
}
Firstly, I would start using the Material Design library in order to be up to date.
So I would add in my build.gradle (app) :
implementation 'com.google.android.material:material:1.5.0'
Then your style should look something like this:
<style name="Theme.QuizApp" parent="Theme.MaterialComponents.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</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:windowFullscreen">true</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="textAppearanceSubtitle1">#style/TextAppearance.App.test</item>
<!-- Customize your theme here. -->
</style>
<style name="TextAppearance.App.test" parent="TextAppearance.MaterialComponents.Subtitle1">
<item name="hintTextColor">#color/purple_gray</item>
<item name="colorControlNormal">#color/purple_gray</item>
<item name="colorControlActivated">#color/purple_gray</item>
<item name="colorControlHighlight">#color/purple_gray</item>
<item name="android:textColorHint">#color/purple_gray</item>
<item name="boxStrokeErrorColor">#color/purple_gray</item>
</style>
Don't know how your design should look like in the XML so I just left the remaining attributes as it was in the style.
and your MainActivity should become:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btn_start: Button = findViewById(R.id.btn_start)
val et_name: TextInputLayout = findViewById(R.id.et_name)
btn_start.setOnClickListener {
if (et_name.editText?.editableText.isNullOrEmpty()) {
et_name.setError("")
Toast.makeText(this, "Enter name", Toast.LENGTH_LONG).show()
}else{
val intent = Intent(this,QuizQuestionActivity::class.java)
intent.putExtra(Constants.USER_NAME,et_name.text.toString())
startActivity(intent)
}
}
}
}
Lastly, in your activity layout you will use that style we created (You will have to adjust that on your project):
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Default"
style="#style/TextAppearance.App.test"
android:layout_margin="10dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/default_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</com.google.android.material.textfield.TextInputLayout>
Let me know if it worked, In my small test project it looks good :)
My small suggestions in general are:
Do not to use findViewById since it is not good for performance for the app if you get in the future a lot of views inside your XML. I would suggest you to use viewBinding or DataBinding.
Try to add the same amount of spaces between your code so that it looks cleaner
Try to extract your Strings, dimensions into xml so that you can re-use them here you can find an article about it https://suragch.medium.com/using-dimens-xml-in-android-10dec2fe485c and one for strings https://riptutorial.com/android/example/13829/working-with-strings-xml-file
Related
I'm trying to following the documentation from Material 3 for checkboxes:
https://github.com/material-components/material-components-android/blob/master/docs/components/Checkbox.md
At the very beginning it states:
Note: <CheckBox> is auto-inflated as
<com.google.android.material.button.MaterialCheckBox> via
MaterialComponentsViewInflater when using a Theme.Material3.*
theme.
This does not seem to work for me, can someone please explain why the checkbox is not auto-inflated as a MaterialCheckBox?
Both theme files are using: Theme.Material3.*
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ParentChildCheckboxes" parent="Theme.Material3.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</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">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ParentChildCheckboxes" parent="Theme.Material3.Dark.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
Layout file:
<?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=".MainActivity">
<CheckBox
android:id="#+id/checkbox_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/label_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/checkbox_child_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_1"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_parent" />
<CheckBox
android:id="#+id/checkbox_child_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_2"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_child_1" />
<CheckBox
android:id="#+id/checkbox_child_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_3"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_child_2" />
<CheckBox
android:id="#+id/checkbox_child_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_4"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_child_3" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity file:
package com.example.parentchildcheckboxes
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.parentchildcheckboxes.databinding.ActivityMainBinding
import com.google.android.material.checkbox.MaterialCheckBox.STATE_INDETERMINATE
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val checkBoxParent = binding.checkboxParent
checkBoxParent.checkedState = STATE_INDETERMINATE
}
}
I cant use .checkedState on checkBoxParent because it's not treated as a MaterialCheckBox:
When I hover on the val checkBoxParent , I see: val checkBoxParent: CheckBox and expected: val checkBoxParent: MaterialCheckBox.
When I change: val checkBoxParent = binding.checkboxParent to: val checkBoxParent = binding.checkboxParent as MaterialCheckBox:
val checkBoxParent = binding.checkboxParent as MaterialCheckBox
checkBoxParent.checkedState = STATE_INDETERMINATE
it works fine.
Why is the checkbox not auto-inflated as a MaterialCheckBox? as stated in the documentation?
Changing the <CheckBox> tag to: <com.google.android.material.checkbox.MaterialCheckBox> solved the issue for me:
<?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=".MainActivity">
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/label_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox_child_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_1"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_parent" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox_child_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_2"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_child_1" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox_child_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_3"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_child_2" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox_child_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/label_child_4"
app:layout_constraintStart_toStartOf="#+id/checkbox_parent"
app:layout_constraintTop_toBottomOf="#+id/checkbox_child_3" />
</androidx.constraintlayout.widget.ConstraintLayout>
I want to change the colour of OK and Cancel text colour in date picker dialogue to black , but it remains white only. I used
<item name="android:textColor">#000000</item>
in the date picker style , to change the colour of the OK text but it is not working !! What's the problem and how to change its colour ?
// themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.DOBCalc" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</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. -->
<item name="fontFamily">#font/font9</item>
</style>
<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/txtBg</item>
<!--selected Item color-->
<item name="colorControlActivated">#color/txtBg</item>
<!-- arrow bordercolor(<>)-->
<item name="android:selectableItemBackgroundBorderless">#color/white</item>
<!-- Highlight item color-->
<item name="colorControlHighlight">#color/bgColor</item>
<!--Calender Background color -->
<item name="android:windowBackground">#color/white</item>
<!-- Ok Cancel Color-->
<item name="android:textColor">#000000</item>
<!-- Week TextColor-->
<item name="android:textColorSecondary">#color/txtBg</item>
<!-- Calender Number color arrow color (< >) -->
<item name="android:textColorPrimary">#000000</item>
<!--day , month-->
<item name="android:textColorPrimaryInverse">#ffffff</item>
<!-- year-->
<item name="android:textColorSecondaryInverse">#ffffff</item>
</style>
// MainActivity.kt file
package com.nandini.android.dobcalc
import android.app.DatePickerDialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import java.text.SimpleDateFormat
import java.util.*
class MainActivity : AppCompatActivity() {
private var dateTv : TextView?=null
private var minTv : TextView?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btnDatePicker : Button = findViewById(R.id.btnDatePicker)
dateTv=findViewById(R.id.date_tv)
minTv=findViewById(R.id.min_tv)
btnDatePicker.setOnClickListener {
datePicker()
}
}
private fun datePicker ()
{
val myCalender = Calendar.getInstance()
val year = myCalender.get(Calendar.YEAR)
val month = myCalender.get(Calendar.MONTH)
val day = myCalender.get(Calendar.DAY_OF_MONTH)
val dpd = DatePickerDialog(this,R.style.datepicker,
{ _, selectedYear, selectedMonth, selectedDay ->
Toast.makeText(this,"Year was $selectedYear , ${selectedMonth+1}'s $selectedDay day.",Toast.LENGTH_SHORT).show()
val selectedDate="$selectedDay/${selectedMonth+1}/$selectedYear"
dateTv?.text = selectedDate
val sdf= SimpleDateFormat("dd/MM/yyyy",Locale.ENGLISH)
val theDate=sdf.parse(selectedDate)
theDate?.let {
val selectedDateInMin=theDate.time / 60000
val currentDate=sdf.parse(sdf.format(System.currentTimeMillis()))
currentDate?.let {
val currentDateInMin=currentDate.time/60000
val differenceInMin = currentDateInMin-selectedDateInMin
minTv?.text=differenceInMin.toString()
}
} },year,month,day)
dpd.datePicker.maxDate=System.currentTimeMillis()-86400000
dpd.show()
}
}
// activity_main.xml
<?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:background="#color/bgColor"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate your"
android:textSize="25sp"
android:textStyle="bold"
android:textAllCaps="true"
android:layout_marginTop="16dp"
android:textColor="#color/txtColor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:textSize="25sp"
android:padding="10dp"
android:background="#color/txtBg"
android:textStyle="bold"
android:textAllCaps="true"
android:layout_marginTop="16dp"
android:textColor="#color/txtColor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Minutes"
android:textSize="25sp"
android:textStyle="bold"
android:textAllCaps="true"
android:layout_marginTop="16dp"
android:textColor="#color/txtColor" />
<Button
android:id="#+id/btnDatePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#D9EADD"
android:layout_margin="16dp"
android:text="Select Date"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#color/txtBg"/>
<TextView
android:id="#+id/date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00.00.00"
android:layout_marginTop="16dp"
android:textAllCaps="true"
android:textColor="#color/txtColor"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Minutes"
android:textSize="20sp"
android:textStyle="bold"
android:textAllCaps="false"
android:layout_marginTop="8dp"
android:textColor="#98B0A8" />
<TextView
android:id="#+id/min_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="35sp"
android:textStyle="bold"
android:textAllCaps="true"
android:layout_marginTop="25dp"
android:textColor="#color/txtColor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Minutes"
android:textSize="25sp"
android:textStyle="bold"
android:textAllCaps="false"
android:layout_marginTop="8dp"
android:textColor="#98B0A8" />
</LinearLayout>
//colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#1d302b</color>
<color name="purple_700">#0f1815</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="bgColor">#49796B</color>
<color name="txtColor">#ffffff</color>
<color name="txtBg">#2c4940</color>
<color name="buttonBg">#D9EADD</color>
</resources>
Add this code :-
dpd.show()
dpd.getButton(DatePickerDialog.BUTTON_NEGATIVE).setBackgroundColor(Color.GREEN)
xml attributes:
colorOnPrimary -> For the text color of OK/CANCEL buttons
You must add this attribute to the dialog style.
I am trying to change color of home arrow indicator in custom toolbar.
There is list of examples that I found but nothing worked for me.
Here is my layout
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/title_bar_toolbar_id"
app:theme="#style/ToolbarColoredBackArrow"
app:popupTheme="#style/AppTheme"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:colorControlNormal="#color/hamburger_color"
android:background="#color/custom_theme_color" >
<LinearLayout
android:id="#+id/base_title_bar_toolbar_id_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/activity_calendar_toolbar_change_view_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/select_semester_view"
android:layout_gravity="center_vertical"
android:padding="10dp" />
<TextView
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/base_title_bar_toolbar_header"
android:layout_weight="0.1"
style="#style/CustomToolBarTitleStyleBase"
android:text="#string/calendar" />
<ImageView
android:padding="13dp"
android:id="#+id/activity_calendar_toolbar_save_date_to_calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/save_date_to_calendar"
android:layout_gravity="center_vertical|start" />
<ImageView
android:id="#+id/activity_calendar_toolbar_select_semester_to_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/select_semester_to_show"
android:layout_gravity="center_vertical|start"
android:padding="13dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
The styles are:
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#color/hamburger_color</item>
<item name="android:textColorPrimary">#color/hamburger_color</item>
<item name="colorControlNormal">#color/hamburger_color</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/custom_theme_color</item>
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
<!-- Support library com`enter code here`patibility -->
<item name="background">#color/custom_theme_color</item>
<item name="titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
</style>
I tried all possibilities that I found in examples,
but nothing worked for me.
Haha, this is one of the most frustrating styling issues in Android right now...
Try creating a style like this
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorSecondary">#000000</item>
</style>
and using it in your Activity (you will probably want to merge it with your current style, as it is just the parent and this one param that matters) and of course replace the #000000 with some other color.
First of all you don't need a separate ImageView for your arrow navigation button. Just use the one from support design resources which will resize automatically according to the screen size.
Drawable upArrow = getResources().getDrawable(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(upArrow);
I want to build a theme for my app. But it seems like my LiestView item don't apply the values.
This is the styles.xml:
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:textViewStyle">#style/TextView</item>
</style>
<style name="TextView" parent="android:Widget.TextView">
<item name="android:layout_margin">8dp</item>
<item name="android:padding">0dp</item>
<item name="android:textColor">#87000000</item>
<item name="android:textSize">18sp</item>
</style>
in my activity i use a Listview with Custom Adapter but the TextViews from my item.xml did'nt have a margin:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical"
tools:context="de.resper.enigma2chromecast.mainLive" >
<TextView
android:id="#+id/channelName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:id="#+id/channelLine1"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
what ever you designed xml, put in android manifest file in application theme
<application android:theme="#style/CustomTheme">
I've been trying to fix this issue for hours now but it looks like I'm the only one having it.
I shouldn't see the number above and below the blue line. Here is the XML
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:useDefaultMargins="true"
android:layout_margin="3dp"
app:columnCount="3"
app:rowCount="7">
........
<NumberPicker
app:layout_column="1"
app:layout_row="3"
android:id="#+id/n_of_dies"
style="#style/inputNumbers"
android:layout_width="wrap_content"
app:layout_gravity="fill_horizontal"
/>
<NumberPicker
app:layout_column="1"
app:layout_row="4"
app:layout_gravity="fill_horizontal"
android:id="#+id/carbon_content"
style="#style/inputNumbers"
android:layout_width="wrap_content"
app:layout_gravity="fill_horizontal"
/>
........
The content of Input numbers is
<style name="inputNumbers">
<item name="android:padding">10dp</item>
</style>
any ideas?
Given the problem is how you're using the paddings I'd recommend to take a look at the widget style (the Holo variation) if you want to change the default look:
...
<style name="Widget.NumberPicker">
<item name="android:internalLayout">#android:layout/number_picker</item>
<item name="android:orientation">vertical</item>
<item name="android:fadingEdge">vertical</item>
<item name="android:fadingEdgeLength">50dip</item>
</style>
...
<style name="Widget.Holo.NumberPicker" parent="Widget.NumberPicker">
<item name="android:internalLayout">#android:layout/number_picker_with_selector_wheel</item>
<item name="android:solidColor">#android:color/transparent</item>
<item name="android:selectionDivider">#android:drawable/numberpicker_selection_divider</item>
<item name="android:selectionDividerHeight">2dip</item>
<item name="android:selectionDividersDistance">48dip</item>
<item name="android:internalMinWidth">64dip</item>
<item name="android:internalMaxHeight">180dip</item>
<item name="virtualButtonPressedDrawable">?android:attr/selectableItemBackground</item>
</style>