减少 AlertDialog.Builder 组件的字体大小 [英] Reducing font size of AlertDialog.Builder's components
问题描述
我使用以下代码创建了一个 AlertDialogue
:
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.
推荐答案
我能够通过样式实现这一点.我将此样式添加到值目录中的 styles.xml
文件中:
I was able to achieve this through styles. I added this style to my styles.xml
file in the values directory:
<style name="AlertDialogTheme" parent="android:Theme.Dialog">
<item name="android:textSize">14sp</item>
</style>
然后在创建 AlertDialog
时,我将活动上下文包装在 ContextThemeWrapper
中并将其传递到 Builder
构造函数:
Then when creating the AlertDialog
, I wrapped the activity context in a ContextThemeWrapper
and passed that into the Builder
constructor:
ContextThemeWrapper cw = new ContextThemeWrapper( this, R.style.AlertDialogTheme );
AlertDialog.Builder b = new AlertDialog.Builder( cw );
这会为对话框中的列表项生成更小的文本大小.
This produced smaller text size for the list items in the dialog.
这篇关于减少 AlertDialog.Builder 组件的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!