if i use TimePicker/TimePickerDialog in my app i'm getting timePickerMode="spinner" styled widget though what i'm looking for is timePickerMode="clock". this is the style I've done
<style name="timePicker_dialog parent="android:Theme.Material.Light">
<item name="timePickerMode">clock</item>
</style>
and I've set this res as the style in the TimePicker via it's TimePickerDialog(), butt i'm still getting the spinner. is it device dependent? my phone is running v4.4.4? if not, what am i missing here. thanks!
As of late 2020, MaterialTimePicker is in the beta version of the Material package.
Therefore you can add the following to your app Gradle:
dependencies { ...
implementation 'com.google.android.material:material:1.3.0-beta01'
}
And then use MaterialTimePicker like so:
MaterialTimePicker materialTimePicker = new MaterialTimePicker.Builder()
.setTimeFormat(clockFormat)
.setHour(hour)
.setMinute(minute)
.build();
materialTimePicker.show(requireFragmentManager(), "fragment_tag");
Try add dependencies compile 'com.android.support:appcompat-v7:23.1.0'
i think use appcompat's theme under 5.0
parent="Theme.AppCompat.Light"
Related
[Disclaimer: DEPRECATED - Digits has changed implementation and ownership. The question/answer is outdated]
I have been using Digits in my Android production app for few months now without any issues. Recently Digits was upgraded to version 2.0.0. I tried upgrading my implementation for the same by following Digits upgrade guide. Everything is working as expected but theme.
My implementation:
In my app, in the activity which extends Application, I have initialized digits as given in docs, and post that used the following code to set theme:
new Digits.Builder().withTheme(R.style.CustomDigitsTheme).build();
where CustomDigitsTheme is:
<style name="CustomDigitsTheme" parent="Theme.AppCompat.Light">
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColorSecondary">#color/text_hint</item>
<item name="android:textColorLink">#color/accent</item>
<item name="dgts__accentColor">#color/accent</item>
<item name="dgts__logoDrawable">#drawable/logo</item>
</style>
Note that Digits provide another way to set theme (using DigitsAuthButton). But I can't use it because in my implementation I'm using regular Button.
[Disclaimer: DEPRECATED - Digits has changed implementation and ownership. The question/answer is outdated]
Solved.
Silly to put this code:
new Digits.Builder().withTheme(R.style.CustomDigitsTheme).build();
instead of:
Fabric.with(this, new TwitterCore(twitterAuthConfig), new Digits.Builder().withTheme(R.style.CustomDigitsTheme).build());
I am using the new Theme.AppCompat.DayNight added in Android Support Library 23.2
On Android 5.1 it works well.
On Android 6.0, activity looks like using light theme, but dialog looks using dark theme.
My Application class:
public class MyApplication extends Application {
static {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
}
}
My styles.xml
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="Dialog.Alert" parent="Theme.AppCompat.DayNight.Dialog.Alert"/>
My code to show a dialog:
new AlertDialog.Builder(mContext, R.style.Dialog_Alert)
.setTitle("Title")
.setMessage("Message")
.show();
Google have fix it in support 23.2.1
Old answer:
On Android 6.0, system's night mode setting defalut is UiModeManager.MODE_NIGHT_NO, it will change Resources.Configuration.uiMode before onCreate is called. However, support library apply its night mode setting in onCreate in AppCompatActivity, it's too late, I think thats why it not work on 6.0.
So if we can Override getResources() in AppCompatActivity and change uiMode.
Old answer:
Here are code to fix not work on Android 6.0
public class Application extends android.app.Application {
static {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_);
}
#Override
public void onCreate() {
super.onCreate();
// add this code for 6.0
// DO NOT DO THIS. It will trigger a system wide night mode.
// This is the old answer. Just update appcompat.
// UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
// uiManager.setNightMode(UiModeManager.MODE_NIGHT_);
}
}
Note: If your app don't have location permission, your app will not have the same calculate result of system. It means it is possible support library thinks it is night now when system not, this will cause some of your UI looks dark some light.
The best way is wait for Google to fix it.
The best solution is to update context with proper config. Here is a snippet of what I do:
public Context setupTheme(Context context) {
Resources res = context.getResources();
int mode = res.getConfiguration().uiMode;
switch (getTheme(context)) {
case DARK:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
mode = Configuration.UI_MODE_NIGHT_YES;
break;
case LIGHT:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
mode = Configuration.UI_MODE_NIGHT_NO;
break;
default:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
break;
}
Configuration config = new Configuration(res.getConfiguration());
config.uiMode = mode;
if (Build.VERSION.SDK_INT >= 17) {
context = context.createConfigurationContext(config);
} else {
res.updateConfiguration(config, res.getDisplayMetrics());
}
return context;
}
Then use the context in your Application like so
#Override
protected void attachBaseContext(Context base) {
Context context = ThemePicker.getInstance().setupTheme(base);
super.attachBaseContext(context);
}
Add getDelegate().applyDayNight(); after setDefaultNightMode.
This issue was reported on https://code.google.com/p/android/issues/detail?id=201910
But after release of Android Support Library, revision 23.2.1 (March 2016). This issue has been resolved.
Fixed a compatibility issue with Night Mode and API level 23
update Support Library to Android Support Library to 23.2.1
As of now, no Gradle dependency is needed to enable the night mode other than androidx.appcompat:appcompat:1.0.2 which will already be present. Make sure to change the default theme from Theme.AppCompat.Light.DarkActionBar to Theme.AppCompat.DayNight.DarkActionBar in the styles.xml file and then do AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) to switch to the night mode. I have tested it in APIv23(Android 6.0) and above and it is working fine.
For a better explanation see this codelab by Android
just add this in your values-v21
<style name="Theme.AppCompat.DayNight">
work for me
done.
I'm trying to add the new Android 5.0 Material Design Datepicker to my pre 5.0 application using AppCompat. I've added
compile "com.android.support:appcompat-v7:21.0.0"
to my build.gradle file and updated my Theme to:
<?xml version="1.0" encoding="utf-8"?>
<style name="AppTheme.Base" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
but the Datepicker still looks like this:
And not like this:
Can anybody tell me how to get the new datepicker to work on pre 5.0 devices?
Thanks in advance.
Update:
As well pointed out by jfcartier, there's now also MaterialDateTimePicker. It's probably a nicer solution than the one below since it has a nice themable API.
You could try the android-betterpickers library. It has a CalendarDatePickerDialog widget that looks like the one you want. It provides a light and a dark theme, but for customizing colors you'd have to add it as a library project and change the code yourself.
Usage is pretty straightforward once you add the library to your project.
// Create date picker listener.
CalendarDatePickerDialog.OnDateSetListener dateSetListener = new CalendarDatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(CalendarDatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) {
// Set date from user input.
Calendar date = Calendar.getInstance();
date.set(Calendar.HOUR_OF_DAY, 9);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.YEAR, year);
date.set(Calendar.MONTH, monthOfYear);
date.set(Calendar.DAY_OF_MONTH, dayOfMonth);
// Do as you please with the date.
}
};
// Create dismiss listener.
CalendarDatePickerDialog.OnDialogDismissListener dismissListener = new CalendarDatePickerDialog.OnDialogDismissListener() {
#Override
public void onDialogDismiss(DialogInterface dialoginterface) {
// Do something when the user dismisses the dialog.
}
};
// Show date picker dialog.
CalendarDatePickerDialog dialog = new CalendarDatePickerDialog();
dialog.setOnDateSetListener(dateSetListener);
dialog.setOnDismissListener(dismissListener);
dialog.setThemeDark(false);
dialog.show(getSupportFragmentManager(), "DATE_PICKER_TAG");
The end result should look like this (sorry for the poor quality).
Material components is the recommended way for date picker
With the Material Components for Android you can use the new MaterialDatePicker.
add the following to your build.gradle
implementation 'com.google.android.material:material:1.1.0'
For kotlin
val builder = MaterialDatePicker.Builder.datePicker()
val picker = builder.build()
picker.show(parentFragmentManager, "date_picker_tag")
For Java
MaterialDatePicker.Builder<Long> builder =
MaterialDatePicker.Builder.datePicker();
MaterialDatePicker<Long> picker = builder.build();
picker.show(getSupportFragmentManager(), picker.toString());
It supports the following configurations
portrait - mode date picker
landscape - mode date picker
date range picker
Mobile input picker
Additional reference
Here is the official design guideline
A complete demo app can be found here
I liked this library. It's a clone of Flavien Laurent Date and Time Picker with some improvements. Both of them are based on Official Google Date and Time Picker for Android 4.3+ but adapted for Android 2.1+.
Is there a way to activiate holo theme for native menus (in my case, a "ContextMenu" hacked out of an AlertDialog) in a trigger android app?
The answer I linked to in my comment turned out to work.
A quick example of how to use this in a plugin:
Dialog dialog = new Dialog(new ContextThemeWrapper(ForgeApp.getActivity(), android.R.style.Theme_Holo));
dialog.setTitle("Hello");
dialog.show();
i have update my ADt18.when i run my early app and sdk2.3,the eclipse give me mistake,the mistake appear at res\value\style, the detail is:
<style name="RatingBarSmall" parent="#android:Widget.RatingBar.Small">
<style name="ListSeparator" parent="#android:style/Widget.TextView.ListSeparator.White">
i found the RatingBar.Small have not support,how to modify it. why update the adt
the style not to useful
Google doesn't allow anymore these kind of parents...
http://daniel-codes.blogspot.com.es/2011/08/new-to-android-more-style-restrictions.html