is it possible to add an outline and hide the mm/dd/yyyy text in material design date picker :
https://material.io/components/date-pickers#anatomy
I am trying to make it such that the outline of textfield should be customizable.
Any suggestions?
You can customize the style of the TextField using:
MaterialDatePicker.Builder.datePicker()
.setTheme(R.style.ThemeOverlay_App_DatePicker)
.build()
with:
<style name="ThemeOverlay.App.DatePicker" parent="#style/ThemeOverlay.MaterialComponents.MaterialCalendar">
<!-- Customize text field of the text input mode. -->
<item name="textInputStyle">#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
</style>
Related
Project has the design of time picker dialog.
the design as follows
then default dialog design is like below
I want the top section of this time picker dialog should be same as the expected design.
I have tried following xml code. nothing helped.
<TimePicker
android:id="#+id/timePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numbersBackgroundColor="#ddd"
android:overScrollMode="never"
android:headerTimeTextAppearance="#drawable/bg_time"
android:headerAmPmTextAppearance="#color/yellow"
android:amPmBackgroundColor="#color/yellow"
android:headerBackground="#android:color/transparent"
/>
And I have added following code to set the title color to transparent. so that I can put my view on the top section.
android:headerTextColor = "#android:color/transparent"
but it says and threw the error
"Unknown Attribute android:headerTextColor"
. in the design part of the XML layout, it set the transparent color to title. but when I run the app it threw the error of
"Android resource linking failed".
Use Material TimePicker to achieve the following design
val picker = MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_12H)
.setHour(12)
.setMinute(10)
.setTitleText("Select Appointment time")
.build()
To show dialog
picker.show(supportFragmentManager, picker.toString())
Using theme attributes and styles in res/values/styles.xml to change color according to your need:
<style name="Theme.App" parent="Theme.MaterialComponents.*">
...
<item name="colorPrimary">#color/shrine_pink_100</item>
<item name="colorOnPrimary">#color/shrine_pink_900</item>
<item name="colorOnSurface">#color/shrine_pink_100</item>
<item name="chipStyle">#style/Widget.App.Chip</item>
</style>
You need to create a custom style in themes.xml. And then set that theme/style to your time picker in xml. This is example of a style:
<style name="MyTimePickerWidgetStyle" parent="#android:style/Widget.Material.TimePicker">
<item name="android:headerBackground">#color/stayGray</item>
<item name="android:numbersTextColor">#fff</item>
<item name="android:numbersInnerTextColor">#fff</item>
<item name="android:numbersSelectorColor">#color/stayGray</item>
<item name="android:amPmTextColor">#fff</item>
</style>
This is how you set style to time picker in xml.
<TimePicker
android:id="#+id/timePickerGoal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/MyTimePickerWidgetStyle"
style="#style/MyTimePickerWidgetStyle"/>
I have a data picker:
val builder = MaterialDatePicker.Builder.dateRangePicker()
val picker = builder.build()
picker.show(childFragmentManager, picker.toString())
and it's status bar color black:
I want it to be transparent like in fragment which hosts this DataPicker:
how to do it?
After some in-depth research of the theming of the material date picker, I was able to figure it out:
In your activity theme you have to add
<item name="materialCalendarFullscreenTheme">#style/CustomMaterialCalendarFullscreenTheme</item>
And create the theme the following way
<style name="CustomMaterialCalendarFullscreenTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="android:windowIsFloating">false</item>
</style>
You could add a custom status bar color by adding this to the CustomMaterialCalendarFullscreenTheme:
<item name="android:statusBarColor">#color/someCoolColor</item>
Note: If you are not interested in what caused the problem you could stop reading here!
The reason is that one of the ancestors of ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen has android:windowIsFloating set to true and if the 'floating' content is very big (as in our case, it is fullscreen) Android decides to change the status bar color to black.
i have used range date picker from google material with this library
implementation 'com.google.android.material:material:1.2.0-alpha02'
this is my code
MaterialDatePicker.Builder<Pair<Long, Long>> builder =
MaterialDatePicker.Builder.dateRangePicker();
CalendarConstraints.Builder constraintsBuilder = new CalendarConstraints.Builder();
builder.setCalendarConstraints(constraintsBuilder.build());
MaterialDatePicker<Pair<Long,Long>> picker = builder.build();
assert getFragmentManager() != null;
picker.show(getFragmentManager(), picker.toString());
i want to custom the dialog picker change text field,make dialog not full screen etc..
how can i make all this modifications
About the fullscreen.
The range picker should cover the entire screen (default = dialog for single date, fullscreen for range).
However you can change this behavior in your style.
You can use the setTheme method to apply a theme overlay:
//To apply a dialog
builder.setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar);
//To apply the fullscreen:
builder.setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar_Fullscreen);
Note: it requires at least the version 1.2.0-alpha01.
As alternative you can add in your app theme the materialCalendarFullscreenTheme attribute.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="materialCalendarFullscreenTheme">#style/CustomThemeOverlay_MaterialCalendar_Fullscreen</item>
</style>
where:
<style name="CustomThemeOverlay_MaterialCalendar_Fullscreen"
parent="#style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="materialCalendarStyle">#style/Custom_MaterialCalendar.Fullscreen</item>
</style>
Here you can override the value with the android:windowFullscreen attribute:
<style name="Custom_MaterialCalendar.Fullscreen"
parent="#style/Widget.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="android:windowFullscreen">false</item>
</style>
About the strings.
Currently there isn't a method to change the strings.
The only existing method is builder.setTitleText to change the title.
However you can override all the existing strings in your project, but this workaround can stop to run in the next releases.
For example:
<string name="mtrl_picker_save" description="Confirms the selection [CHAR_LIMIT=12]">....</string>
<string name="mtrl_picker_text_input_date_range_start_hint" description="Label for the start date in a range selected by the user [CHAR_LIMIT=60]">...</string>
<string name="mtrl_picker_text_input_date_range_end_hint" description="Label for the end date in a range selected by the user [CHAR_LIMIT=60]">...</string>
Here you can find all the strings used by the material calendar in the 1.2.0-alpha02.
Basically, you should play with styles. In your AppTheme add an item materialCalendarTheme with your custom style that inherits parent ThemeOverlay.MaterialComponents.MaterialCalendar, and change the style.
Change text field - call MaterialDatePicker.Builder function setTitleText()
Make dialog not full screen - you can't change it for date range picker, the documentation says that it is fullscreen by default
Mobile date range pickers allow selection of a range of dates. They
cover the entire screen.
Here's documentation https://material.io/components/pickers
Here's how I tweaked some colors to match my theme:
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="materialCalendarTheme">#style/ThemeMaterialCalendar</item>
</style>
<style name="ThemeMaterialCalendar" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="buttonBarPositiveButtonStyle">#style/ThemeMaterialCalendarButton</item>
<item name="buttonBarNegativeButtonStyle">#style/ThemeMaterialCalendarButton</item>
<item name="materialButtonStyle">#style/ThemeMaterialCalendarTextButton</item>
</style>
<style name="ThemeMaterialCalendarButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">?themeTextColorPrimary</item>
</style>
<style name="ThemeMaterialCalendarTextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
<item name="android:textColor">?themeTextColorPrimary</item>
<item name="iconTint">?themeTextColorPrimary</item>
</style>
Changing between fullscreen and dialog version can be as easy as that:
fullscreen:
val picker = MaterialDatePicker.Builder.dateRangePicker().setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar_Fullscreen).build()
dialog:
val picker = MaterialDatePicker.Builder.dateRangePicker().setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar).build()
While the posted answer totally work there seems to be no need to set the materialCalendarTheme globally - you can just set it to via the MaterialDatePicker.Builder and setTheme(int themeResId) method. Following an example how they do it in the Material Design Catalog App.
val datePicker = MaterialDatePicker.Builder.dateRangePicker().apply {
context?.resolveOrNull(R.attr.materialCalendarTheme)?.let {
setTheme(it)
}
setCalendarConstraints(getConstraints())
}.build()
// ...
resolveOrThrow helper method:
fun Context.resolveOrNull(#AttrRes attributeResId: Int): Int? {
val typedValue = TypedValue()
if (theme.resolveAttribute(attributeResId, typedValue, true)) {
return typedValue.data
}
return null
}
This way you DatePicker dialog won't be full screen but a regular dialog.
"i'm using google's material date picker 'com.google.android.material:material:1.1.0-alpha10' version,and i want to disable the input method through keyboard,is there a way to disable/hide the edit method"
you can use custom style as workaround to disable calendar input mode toggle. This toggle uses style attribute materialCalendarHeaderToggleButton, so:
<style name="Widget.AppTheme.MaterialDatePicker" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="materialCalendarHeaderToggleButton">#style/Widget.AppTheme.MaterialCalendar.HeaderToggleButton</item>
<style name="Widget.AppTheme.MaterialCalendar.HeaderToggleButton" parent="Widget.MaterialComponents.MaterialCalendar.HeaderToggleButton">
<item name="android:visibility">gone</item>
And after that apply theme with:
MaterialDatePicker.Builder.dateRangePicker()
.setTheme(R.style.Widget_AppTheme_MaterialDatePicker)
You can access PickerDialogs View and then make this button Gone but make sure to wait for the dialogs view to initialize first by adding this line after dialog.show method
activity?.supportFragmentManager?.executePendingTransactions()
then
(picker.view?.findViewById(R.id.mtrl_picker_header_toggle) as View).visibility = View.GONE
I am developing an application where I need to show a dialog with a DatePicker in it. Now my designs are such that the DatePicker should be Spinner mode as was prior to Material Design. I want it to look something like this -
I'm trying to make my custom view of the dialog and then use datepicker spinner in android but then I am not able to change the color of the selected number to Red. How to change the color of the numbers selected in between to red as shown in the image?
Can someone help me on this?
The color depends on the theme set on the Dialog used to inflate the layout.
Set up a basic theme like this:
<style name="PickerDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/error_red</item>
</style>
where the colorAccent attribute applies the color you want to your DatePicker