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:
private static int mTextSize = 5;
private static int mFirstVisible = -1;
private static int mLastVisible = -1;
v.post(new Runnable() {
@Override
public void run() {
changeCurrentVisibleSize(ad.getListView());
// ad is the AlertDialog resulted from alertBuilder.create
ad.getListView().setOnScrollListener(
new OnScrollListener() {
@Override
public void onScrollStateChanged(
AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view,
int firstVisibleItem,
int visibleItemCount,
int totalItemCount) {
if (visibleItemCount != 0) {
if (mFirstVisible != firstVisibleItem
|| mLastVisible != (firstVisibleItem
+ visibleItemCount - 1)) {
updateRow((ListView) view);
}
}
}
});
}
});
where the changeCurrentVisibleSize()
and updateRow()
method are:
static void updateRow(ListView listView) {
final int count = listView.getChildCount();
final View firstRow = listView.getChildAt(0);
final View secondRow = listView.getChildAt(count - 1);
if (firstRow instanceof TextView) {
((TextView) firstRow).setTextSize(mTextSize);
((TextView) secondRow).setTextSize(mTextSize);
}
}
static void changeCurrentVisibleSize(ListView listView) {
final int count = listView.getChildCount();
mFirstVisible = listView.getFirstVisiblePosition();
mLastVisible = listView.getLastVisiblePosition();
for (int i = 0; i < count; i++) {
final View rowView = listView.getChildAt(i);
if (rowView instanceof TextView) {
((TextView) rowView).setTextSize(mTextSize);
}
}
}
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).