portal47 portal47 - 1 year ago 118
Android Question

How to set a custom title on time picker?

I'm making a date picker with a title but the view its ugly because there is no margin bottom, how can i make a margin to make it little pretty?timepickerdialog screenshot

As you can see it's very ugly.

My code:

if(endTime.isEmpty() || startTime.isEmpty()){

int CustomHour = 12;
int CustomMinute = 00;
int hour = CustomHour;
int minute = CustomMinute;

TimePickerDialog tpd = new TimePickerDialog(ActivityAlarm.this, new TimePickerDialog.OnTimeSetListener()

int callCount = 0; //To track number of calls to onTimeSet()
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute)


}, hour, minute, DateFormat.is24HourFormat(ActivityAlarm.this));
tpd.setTitle("Set Time");
// Create a new instance of TimePickerDialog and return it
return tpd;

Answer Source

try this:

In code do this:

        LayoutInflater inflater = this.getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.text_layout, null);
        TextView texts=(TextView) dialogView.findViewById(R.id.textss);
        texts.setText("Start Time");

In xml make a file named:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" />

enter image description here