I am trying to create a time picker for my application..
and when setting the theme to Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
I am getting this output
I am getting a blank space around the dialog box
This is not happening when I am setting it to use the parent activity's theme which is appcompat.noactionbar
//not happening here
return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );
Here is my timepicker code
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{
#Override
public Dialog onCreateDialog(Bundle savedInstanceState){
//Use the current time as the default values for the time picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean is24HourView=true;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String formattedTime = sdf.format(c.getTime());
Log.d("time", formattedTime);
//Create and return a new instance of TimePickerDialog
// return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );
return new TimePickerDialog(getActivity(), android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth,this, hour, minute,is24HourView );
}
I know this is old, but here is a solution.
You could make a custom theme in styles.xml with your chosen theme as a parent, and set it's android:windowBackground attribute to #android:color/transparent:
<style name="TimePickerDialogStyle" parent="#android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar.MinWidth">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Then pass your custom theme to the TimePickerDialog constructor:
new TimePickerDialog(getActivity(), R.style.TimePickerDialogStyle, this, hour, minute, is24HourView);
Change:
android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
with
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT
or
AlertDialog.THEME_HOLO_LIGHT
It should work
Related
This is very weird , I've a timePicker in my custom dialog , the problem is it's looks nice on some version of android but in android 5.0.2 , it gets a black background color like this :
as you can see, the clock background is changed but I've made no changes .
final Dialog dialog = new Dialog(SabadKharid_s1.this, R.style.DialogStyler2);
dialog.setContentView(R.layout.dialogtime);
timePicker = (TimePicker) dialog.findViewById(R.id.timePicker);
timePicker.setIs24HourView(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.show();
dialog.getWindow().setAttributes(lp);
this is the style I use :
<style name="DialogStyler2" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
</style>
How can I fix this problem ?
what ever you pop up in your screen ... the dialogues may have a default theme.
Try using a custom theme for your pop ups ... it will change background color or set custom view for pop up and in layout set parent background as android:background="#andrid:color/transparent"
I can not think of a reason why you have used the time picker in a dialog where you can just use the Material Time Pickers directly.
You can use this for a much easier solution.
https://github.com/wdullaer/MaterialDateTimePicker
TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(
new TimePickerDialog.OnTimeSetListener() {
#Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
//Do your thing
);
timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialogInterface) {
//do your thing for cancel event
}
});
timePickerDialog.setAccentColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
timePickerDialog.show(getFragmentManager(), TAG);
Try using TimePickerDialog.
// Initialize time picker
Calendar c = Calendar.getInstance();
int curHour = c.get(Calendar.HOUR_OF_DAY);
int curMinute = c.get(Calendar.MINUTE);
boolean is24HourView = true;
// Construct time picker dialog
TimePickerDialog dialogTimePicker = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
#Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute)
{
// Do something
}
}, curHour, curMinute, is24HourView);
// Show time picker dialog
dialogTimePicker.setTitle("Time Picker");
dialogTimePicker.show();
Hope this will help~
I'm using a DatePickerDialog in a DialogFragment, which works fine.
I would like to change the colors of:
the background of the action bar
the background of the buttons
the dividers
Here is my DialogFragment:
public class DatePickerDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
{
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// init :
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DatePickerDialogTest, this, year, month, day);
datePickerDialog.getDatePicker().setBackgroundColor(0xFF500000);
return datePickerDialog;
}
...
}
And here is the style:
<style name="DatePickerDialogTest" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:textColorPrimary">#FF00FF00</item>
<item name="colorAccent">#FFFF0000</item>
<item name="android:divider">#android:color/holo_purple</item>
</style>
Every color I use displays properly, except for the backgrounds of the action bar, buttons and dividers.
Is there any way I can easily change those colors?
Thanks.
I'm creating a form that consists of EditTexts which launch DatePickerDialogs and TimePickerDialogs.
Here are the sections of the code:
DatePickerDialog
DatePickerDialog datePicker = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(android.widget.DatePicker view, int chosenYear, int chosenMonth, int chosenDate) {
year = chosenYear;
month = chosenMonth;
date = chosenDate;
set(year, month, date);
}
}, year, month, date);
datePicker.setTitle("Select Date");
datePicker.show();
TimePickerDialog
TimePickerDialog timePicker = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
#Override
public void onTimeSet(android.widget.TimePicker view, int chosenHour, int chosenMinute) {
hour = chosenHour;
minute = chosenMinute;
set(hour, minute);
}
}, hour, minute, false);
timePicker.setTitle("Select Time");
timePicker.show();
Everything works as it should be such as launching the dialogs and setting the date properly. There's this one problem. The previews are not rendered. I don't know why. Hope someone could help. Thanks.
Here are the screenshots:
Notice the white backgrounds.
in your styles.xml add two new styles:
<style name="DatePicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/your_color</item>
</style>
<style name="TimePicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/your_color</item>
</style>
Then refer to these styles in your custom theme as followed:
<item name="android:datePickerDialogTheme" tools:targetApi="21">#style/DatePicker</item>
<item name="android:timePickerDialogTheme" tools:targetApi="21">#style/TimePicker</item>
I have a question about DatePickerDialog displaying.
I want to create date picker dialog with "HoloDialog" theme like this:
DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog, reservationDate, 2014, 1, 1);
Then I will see this result:
As you can see, dialog is displayed with "two borders" around.
I want to create the same dialog as displayed here, but with one border around. Is it possible?
Assuming I understand your question correctly, I think I found a way. Here, we anonymously subclass DatePickerDialog to override onCreate() and set a transparent background for the window.
DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog,
reservationDate, 2014, 1, 1) {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
};
You could also do this with a custom theme instead. For example:
<style name="HoloDialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Then pass that in the DatePickerDialog's constructor:
DatePickerDialog dpd = new DatePickerDialog(this, R.style.HoloDialog,
reservationDate, 2014, 1, 1);
I want a app that sets a alarm according to a time-picker and not a data-picker, i want the alarm to go off every day at the time the time-picker is set at.
I don't want to have a button which becomes a picker i want to use the time-picker icon.
If you want to have a Button without Text, you can use
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_icon"
... />
If you want to set up an Alarm create a new class, that shows TimePicker in FragmentDialog
public static class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Here you get the selected Time, do whatever you want
}
}
And in the Activity, where is the Button:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pick_time"
android:onClick="showTimePickerDialog" />
Set OnclickListener, which starts FragmentDialog with TimePicker
public void showTimePickerDialog(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker");
}
http://developer.android.com/guide/topics/ui/controls/pickers.html#TimePicker
I dont really understand, what are you actually asking for. Clarify your question please.