Reputation: 41
I am using android.support.v7.app.AlertDialog.However, I'm not able to remove the divider.Can anybody tell me how to remove it? thanks.
this is my style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="alertDialogTheme">@style/AppTheme.Dialog.Alert</item>
</style>
<style name="AppTheme.Dialog.Alert" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/colorAccent</item>
</style>
this is my code:
AlertDialog.Builder builder = new AlertDialog.Builder(mSettingsView.getBaseActivity());
builder.setTitle("Ringtone");
builder.setSingleChoiceItems(list, -1, listener1);
builder.setPositiveButton("OK", listener2);
builder.setNegativeButton("Cancel", listener3);
builder.show();
Upvotes: 3
Views: 2910
Reputation: 1085
AlertDialog divider is different in pre-lollipop and lollipop devices. I found, divider colour is Gray in pre-lollipop(pre-material design) devices. So it is visible. But for material design(lollipop) devices, divider colour is transparent, so it seems not visible/present.
To make divider visible across all devices, explicitly make the colour Gray or any other colour.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog alertDialog = builder.create();
ListView listView = alertDialog.getListView();
listView.setDivider(new ColorDrawable(Color.GRAY));
listView.setDividerHeight(1);
alertDialog.show();
Upvotes: 1
Reputation: 280
Are you using the AlertDialog inside a android.support.v4.app.DialogFragment? I always use it this way and I never get the divider in your screen:
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
public class MyDialogFragment extends DialogFragment {
public static MyDialogFragment newInstance(){
return new MyDialogFragment;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate my custom layout
View layout = inflater.inflate(R.layout.my_custom_layout, null);
// Initialize my layout components
...
// Build dialog
builder.setTitle("TITLE")
.setView(layout)
.setPositiveButton("OK", listener)
.setNegativeButton("Cancel", listener);
return builder.create();
}
}
Upvotes: 0