I've created an AlertDialog
using the AlertDialog.Builder
and would like to adjust the placement of the action buttons (Cancel and OK) to improve its appearance.
I've searched and can't seem to find any easy way. Do I have to abandon the AlertDialog.Builder
and add the action button functions to my view and setup all the listeners? If so, how do I determine the text size/color for the action buttons to stay consistent with other AlertDialog
?
popup_tee_selection_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/popup_tee_selection_TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enter_new_tee"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/popup_tee_selection_EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<Switch
android:id="@+id/popup_tee_selection_Switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|start"
android:showText="true"
android:textOff="Men"
android:textOn="Women"
android:thumbTextPadding="10dp"
android:thumb="@drawable/custom_switch_inner_holo_light"
android:track="@drawable/custom_switch_track_holo_light"/>
</LinearLayout>
code fragment
private void popupTeeSelectionEditText() {
View popupView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_tee_selection_edittext, null);
final EditText userInput = (EditText) popupView.findViewById(R.id.popup_tee_selection_EditText);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder
.setView(popupView)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String selectedItem = userInput.getText().toString();
if (DEBUG) Log.w(TAG, "Returned value: '" + selectedItem + "'");
if (listViewAlertDialog != null)
listViewAlertDialog.cancel();
processTeeSelectionCourse(selectedItem);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.show();
}