我想在Android中的AlertDialog中调整按钮的字体大小(正面,负面和中性)。到目前为止,我只看到了标题的字体大小调整和AlertDialog的消息。
以下是我用来创建对话框的代码:
public void showPopUp(){
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
//dialog.setContentView(R.layout.dialog_main);
pvuDB.open();
imageDB.open();
dialog.setTitle("Select Unit and Quantity of Variant");
//set drawables ArrayList here
//here I'm just fetching image paths because my dialog has a listView
//made up of images in its message
drawables = imageDB.fetchDialogImages(getIntent().getStringExtra("productName"),
pvuDB.getVariantOfProduct(getIntent().getStringExtra("productName"), variantPosition));
imageDB.close();
//R.layout.dialog_main is just a plain white layout with a listView
View view = getLayoutInflater().inflate(R.layout.dialog_main, null);
//get unit details here
final ArrayList dialogList = getDialogData();
pvuDB.close();
final ListView lv = (ListView) view.findViewById(R.id.custom_list);
customListAdapterDialog = new CustomListAdapterDialog(OrderForm.this, dialogList);
lv.setAdapter(customListAdapterDialog);
//TODO this one is the dialog that sets the quantity
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, final int position, long id){
//Long listView onclick function here
});
dialog.setView(view);
dialog.show();
}
我知道我可以去使用自定义对话框,但这对我来说太过分了,因为我只是调整按钮的字体大小。
是否可以在不使用自定义对话框的情况下增加/减少AlertDialog中按钮的字体大小?
答案 0 :(得分:3)
首先将这些样式添加到styles.xml
<style name="AlertS" parent="android:Theme.Dialog">
<item name="android:textSize">10sp</item>
</style>
之后,在创建警报对话框时编写此代码。
ContextThemeWrapper con = new ContextThemeWrapper( this, R.style.AlertS );
AlertDialog.Builder bui = new AlertDialog.Builder( con );