I created an AlertDialogue
using the following code :
int selectedModeId=0;
public void sortTypeModeSelection(){
AlertDialog.Builder alertBuilder=new AlertDialog.Builder(WatchListDetailActivity.this);
alertBuilder.setSingleChoiceItems(R.array.watchlist_sorting_modes,selectedModeId, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
switch (which){
case 0:
selectedModeId=0;
break;
case 1:
selectedModeId=1;
break;
case 2:
selectedModeId=2;
break;
case 3:
selectedModeId=3;
break;
case 4:
selectedModeId=4;
break;
case 5:
selectedModeId=5;
break;
case 6:
selectedModeId=6;
break;
case 7:
selectedModeId=7;
break;
}
dialog.cancel();
}
});
alertBuilder.show();
}
I made the alert, but I want to reduce the font size of the list items of the dialog. How can I do this?
Note: Don't recommend inflating a custom layout to accomplish this, I wish to know if there is another approach.
Try out as below :
Its just a way i am showing you the way its possible.
And in layout/menu_items.xml :
I hope it will help you.
Thanks.
I don't see why you would need to change the text size without using a custom layout file like shown in the present answers(unless you're maybe implementing some sort of accessibility option keeping the current platform's look and feel?). Anyway you could still modify the text size by directly modifying the dialog's list. Something like this:
where the
changeCurrentVisibleSize()
andupdateRow()
method are:Increasing the text should work fine, decreasing the text again should work fine(but in this case the row will continue to have a certain height based on the layout file used).
I was able to achieve this through styles. I added this style to my
styles.xml
file in the values directory:Then when creating the
AlertDialog
, I wrapped the activity context in aContextThemeWrapper
and passed that into theBuilder
constructor:This produced smaller text size for the list items in the dialog.
you have to use custom layout for this.
check below code it sure help you
row file: