5

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()              
        @Override
        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;
}
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
GusDev
  • 255
  • 6
  • 20

1 Answers1

7

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");
        tpd.setCustomTitle(dialogView);

In xml make a file named:

text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">
<TextView
    android:id="@+id/textss"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>

enter image description here

Aakash
  • 5,181
  • 5
  • 20
  • 37
  • 1
    i'm not using any xml file – GusDev Aug 12 '15 at 23:04
  • then post your code snippet, it will be easier to modify your code according to requirement – Aakash Aug 12 '15 at 23:06
  • i do that and the app crashes when i try to open the TimePicker, also get an error on "getLayoutInflater" it says "The method getLayoutInflater(Bundle) in the type DialogFragment is not applicable for the arguments ()" – GusDev Aug 12 '15 at 23:50
  • 1
    if you are using fragment then do this: getActivity().getLayoutInflater(); Also not that, add my code before return tpd; – Aakash Aug 12 '15 at 23:52
  • 1
    sorry i had to change this: LayoutInflater inflater = LayoutInflater.from(ActivityAlarm.this); – GusDev Aug 12 '15 at 23:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/86840/discussion-between-aakash-and-portal47). – Aakash Aug 12 '15 at 23:54