Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can TimePicker be used without header on Android

I am using the <TimePicker> widget to enable the user to set the time. However, since I'm embedding the <TimePicker> into one of my views, I'd like to get rid of the TimePicker's header (the crossed out area in the picture).

Default timepicker in Android looks like this:

Question: Is it possible to remove the timepicker's header and use only the analog part of the widget?

AndroidPicker

like image 276
Kornelije Petak Avatar asked Apr 26 '18 04:04

Kornelije Petak


People also ask

How can I change DatePicker size in android?

For example, android:layout_width="15dp" will set the width at a scalable value of 15. You can change 15 to whatever you want. If you want to set a specific pixel size, you can use, for example, 15px .

How do I make my DatePicker smaller?

The android:scaleX="0.7" is what shrinked the visible picker (it works for DatePicker and TimePicker ) and the android:layout_marginLeft="-30dp" allowed for the space to be reduced.


1 Answers

There is no public method in TimePicker to directly hide or show the Time Header. Try the below source code will give us the name of the resource ID for that View, which we can get with the system Resources. Then finding the View, and setting its visibility to GONE.(I haven't tested)

private void hideTimeHeaderLayout(TimePicker picker) {
    final int id = Resources.getSystem().getIdentifier("time_header", "id", "android");
    final View timeLayout = picker.findViewById(id);
    if(timeLayout != null) {
        timeLayout .setVisibility(View.GONE);
    }
}
like image 102
Nas Avatar answered Oct 03 '22 06:10

Nas