Ad
AlertDialog Divider Is Not Showing On Android 4.4 Kitkat
I have alert dialog with four items (Array of strings), I want to add divider between each item and first divider with different color, I saw it on android 4.4 kitkat like this
here's my Alert dialog code
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(getString(R.string.choose_layout));
String[] recyclerViewLayouts = getResources().getStringArray(R.array.RecyclerViewLayouts);
SharedPreferences.Editor editor = sharedPreferences.edit();
dialog.setItems(recyclerViewLayouts, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int index) {
}
}
});
dialog.create();
dialog.show();
I tried to create it with the following code but also not showing
AlertDialog alertDialog = builder.create();
ListView listView = alertDialog.getListView();
listView.setDivider(new ColorDrawable(Color.GRAY));
listView.setDividerHeight(1);
alertDialog.show();
Ad
Answer
[Solved]
after many hours searching I found the problem is that I used the AlertDialog of androidx lib androidx.appcompat.app.AlertDialog
which is not yet supported to add dividers automatically, and I was should use android.app.AlertDialog.Builder
after I changed to it the divider is showing again
The code after update
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);
builder.setTitle(getString(R.string.choose_layout));
String[] recyclerViewLayouts = getResources().getStringArray(R.array.RecyclerViewLayouts);
SharedPreferences.Editor editor = sharedPreferences.edit();
builder.setItems(recyclerViewLayouts, (dialog, index) -> {
}
});
android.app.AlertDialog alertDialog = builder.create();
alertDialog.show();
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad