You can use a custom XML like this:
datepickerdialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<DatePicker
android:id="@+id/dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"/> //delete this line if you want to show calendar too
</RelativeLayout>
Then add a listener to a button (or whatever) and inflate this layout like this:
yourclass.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aggiungiesame);
Button button = (Button) findViewById(R.id.your_id_button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button: {
LayoutInflater inflater = getLayoutInflater();
View customView = inflater.inflate(R.layout.datepickerdialog, null);
DatePicker dp = (DatePicker) customView.findViewById(R.id.dp);
...OTHER CODE HERE
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(customView);
builder.setTitle("Select date:");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
...YOUR CODE HERE...
dialog.dismiss();
}
});
builder.create().show();
break;
}
}
}
Here you set just a button, the 'OK' button!