
是否可以在AlertDialog的正,负和中性按钮中添加drawable?如果是,那怎么样?
解决方法:
由于不推荐使用onPrepareDialog,因此您可以使用onShowListener.
你也应该设置Drawable边界,或者它将被放置在最左边.
下面的代码输出
public class MyDialog extends DialogFragment { @OverrIDe public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle("My Dialog") .setNegativebutton("Cancel", new OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { // Todo auto-generated method stub } }).setPositivebutton("Play", new OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { // Todo auto-generated method stub } }).create(); dialog.setonShowListener(new OnShowListener() { @OverrIDe public voID onShow(DialogInterface dialogInterface) { button button = dialog.getbutton(AlertDialog.button_POSITIVE); // if you do the following it will be left aligned, doesn't look // correct // button.setCompoundDrawablesWithIntrinsicBounds(androID.R.drawable.ic_media_play, // 0, 0, 0); Drawable drawable = getActivity().getResources().getDrawable( androID.R.drawable.ic_media_play); // set the bounds to place the drawable a bit right drawable.setBounds((int) (drawable.getIntrinsicWIDth() * 0.5), 0, (int) (drawable.getIntrinsicWIDth() * 1.5), drawable.getIntrinsicHeight()); button.setCompoundDrawables(drawable, null, null, null); // Could modify the placement more here if desired // button.setCompoundDrawablepadding(); } }); return dialog; }} 总结 以上是内存溢出为你收集整理的android – AlertDialog按钮的图像全部内容,希望文章能够帮你解决android – AlertDialog按钮的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)