java - Fullscreen DatePicker inside Activity -


i trying display datepicker , timepicker widget inside activity i'm calling startactivityforresult. both pickers should match parent layout width. in case, works timepicker datepicker doesn't fill out entire screen.

i tried measuring display size programmatically , setting layoutparams of datepicker inside onresume. unfortunately, didn't work.

how can implement datepicker widget stretches width of parent layout?

datepicker screenshot

enter image description here

timepicker screenshot

enter image description here

activity_date_time_picker.xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent">      <include         android:id="@+id/toolbar"         layout="@layout/toolbar"         android:layout_width="match_parent"         android:layout_height="wrap_content" />      <scrollview         android:id="@+id/scroll_view"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/toolbar">          <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="vertical">              <datepicker                 android:id="@+id/datepicker"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_gravity="center" />              <timepicker                 android:id="@+id/timepicker"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_gravity="center" />          </linearlayout>     </scrollview> </relativelayout> 

onresume method in datetimepickeractivity:

/* ... */ @override protected void onresume() {     super.onresume();      int width = resources.getsystem().getdisplaymetrics().widthpixels;     linearlayout.layoutparams params = (linearlayout.layoutparams) datepicker.getlayoutparams();     params.width = width;     datepicker.setlayoutparams(params); } /* ... */ 

try this

style.xml

<style name="dialogtheme" parent="theme.appcompat.light">         <!-- customize theme here. -->         <item name="colorprimary">@color/colorprimary</item>         <item name="colorprimarydark">@color/colorprimarydark</item>         <item name="coloraccent">@color/coloraccent</item>     </style> 

mainactivity.java apply theme in constructor of date picker (r.style.apptheme)


 datepickerdialog datepickerdialog = new datepickerdialog(getactivity(), r.style.apptheme, this, year, month, day);             datepickerdialog.getdatepicker().setmaxdate(c.gettimeinmillis());             return datepickerdialog; 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -