DataPicker is similar to the old design and the new API.

So the problem is very simple:

I have included DatePicker in my application. Not like DialogDatePicker , but as a View component (more precisely, a View inside a Fragment that is dynamically displayed and removed from the FrameLayout contained in my main FragmentActiviy layout.).

now my problem is that this DataPicker looks like this: enter image description here

and not so:

enter image description here

even when I aim for a higher API, I tried setting my Min SDK to 16 or 17, but it didn't help either.

Does anyone know why this is happening? and how can I show a new kind of data collector? desirable in older versions of Android?

Any help would be appreciated.

Thanks.

EDIT: Code:

DataPickerFragment xml:

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="6.5dp" android:paddingTop="6dp" android:paddingRight="8.5dp" android:paddingBottom="8.5dp" android:background="@drawable/date_picker_background"> <DatePicker android:id="@+id/datePicker" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:paddingBottom="40dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/bCancel" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_weight="1.0" android:onClick="buttonCanceDatePickerOnclick" android:text="@string/cancel" /> <Button android:id="@+id/bSave" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_weight="1.0" android:onClick="buttonSaveDatePickerOnclick" android:text="@string/save" /> </LinearLayout> </FrameLayout> 

DataPickerFramgnet Class:

 public class DatePickerFragment extends Fragment { private Button bSave, bCancel; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.date_picker_fragment_layout, container, false); return rootView; } } 

UPDATE:

Manifast File:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.emildesign.sgreportmanager" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="13" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- Crittercism --> <uses-permission android:name="android.permission.READ_LOGS"/> <uses-permission android:name="android.permission.GET_TASKS"/> <application android:allowBackup="true" android:name="com.emildesign.sgreportmanager.SGRaportManagerAppObj" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <activity android:name="com.emildesign.sgreportmanager.activities.LoginScrActivity" android:screenOrientation="landscape"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.emildesign.sgreportmanager.activities.ReportsTableActivity" android:screenOrientation="landscape"> </activity> <activity android:name="com.emildesign.sgreportmanager.activities.ParametersActivity" android:screenOrientation="landscape"> </activity> <activity android:name="com.crittercism.NotificationActivity"/> </application> 

I found where my problem is, I installed:

 android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 

to make my application fullscreen, and this applied the old data collector style, changing it to:

 android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" 

Creates the following DataPicker:

enter image description here

This is better than before, but this is not the result I am looking for.

+7
source share
5 answers

Set android:targetSdkVersion as 11 or more. Here is an example application demonstrating this .


UPDATE

Firstly, your original DatePicker screenshot is from a dark theme (e.g. Theme.Holo ), while the second screenshot is from a light theme (e.g. Theme.Holo.Light ).

Secondly, the DatePicker documentation has the following opening paragraph:

This class is a date widget. Date can be selected by round, monthly and daily spinners or CalendarView. The spinner set and calendar view are automatically synchronized. The customer can configure whether only the spinners are displayed, or only the calendar view, or both. You can also set the minimum and maximum date from which you can select the dates you want to select.

You can get rid of CalendarView via android:calendarViewShown (or setCalendarViewShown() ). When you try this, you will find that your year counter will appear as soon as the CalendarView disappears.

+4
source

You must use the Golo theme.

So your theme should look like this:

 <style name="AppTheme" parent="@android:style/Theme.Holo"> ... </style> 
+3
source

Responding to your update

Edit

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"

to

android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"

+1
source

Here is a snippet for calling the default device Date And Time Picker

date_time_layout.xml

  <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" > <DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:calendarViewShown="false" > <!-- style="@style/date_picker_style" --> </DatePicker> <TimePicker android:id="@+id/timePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" > </TimePicker> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <Button android:id="@+id/dialogCancel" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="Cancel" /> <Button android:id="@+id/dialogSet" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="Set" /> </LinearLayout> </LinearLayout> </ScrollView> 

Put this method in your class and call it with showDateAndTimePicker ();

 private void showDateAndTimePicker() { final Dialog dialog = new Dialog(this, android.R.style.Theme_DeviceDefault_Dialog); dialog.setContentView(R.layout.date_time_layout); dialog.setCancelable(false); dialog.setTitle("Select Date and Time"); Button set = (Button) dialog.findViewById(R.id.dialogSet); Button cancel = (Button) dialog.findViewById(R.id.dialogCancel); final DatePicker dtp = (DatePicker) dialog .findViewById(R.id.datePicker1); final TimePicker tp = (TimePicker) dialog .findViewById(R.id.timePicker1); set.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Handle Set button dialog.dismiss(); } }); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Handle Cancel button dialog.dismiss(); } }); dialog.show(); } 
0
source

You need to use DialogFragment for the result you are looking for:

http://developer.android.com/guide/topics/ui/controls/pickers.html

-2
source

All Articles