edw*_*win 14 android android-custom-view android-fonts android-alertdialog
我AlertDialogue使用以下代码创建了一个:
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();
}
Run Code Online (Sandbox Code Playgroud)

我发出警报,但我想减少对话框列表项的字体大小.我怎样才能做到这一点?
注意:不建议为自定义布局充气以实现此目的,我想知道是否有其他方法.
Jas*_*son 42
我能够通过风格实现这一目标.我将此样式添加到styles.xmlvalues目录中的文件中:
<style name="AlertDialogTheme" parent="android:Theme.Dialog">
<item name="android:textSize">14sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后在创建时AlertDialog,我将活动上下文包装在a中ContextThemeWrapper并将其传递给Builder构造函数:
ContextThemeWrapper cw = new ContextThemeWrapper( this, R.style.AlertDialogTheme );
AlertDialog.Builder b = new AlertDialog.Builder( cw );
Run Code Online (Sandbox Code Playgroud)
这为对话框中的列表项生成了较小的文本大小.

你必须为此使用自定义布局.

检查下面的代码,它肯定会帮助你
AlertDialog.Builder builder = new AlertDialog.Builder(forgatps.this);
builder.setTitle("Select Your Account");
builder.setAdapter(new ArrayAdapter<String>(forgatps.this,
R.layout.row_email, R.id.textView1, emails),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
MainEmail = emails.get(which);
editEmail.setText("" + MainEmail);
}
});
builder.show();
Run Code Online (Sandbox Code Playgroud)
行文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="26dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12296 次 |
| 最近记录: |