简体   繁体   English

自定义对话框中的android图标

[英]android icon in custom dialog box

I have implemented the following code for the custom dialog box, and hope to also put an icon in the title bar, but fails. 我为自定义对话框实现了以下代码,并希望在标题栏中也放置一个图标,但失败了。 The dialog box pops up without any icon on the left. 对话框弹出,左侧没有任何图标。

final Dialog dialog1 = new Dialog(First.this, android.R.style.Theme_Translucent_NoTitleBar);
        dialog1.requestWindowFeature(Window.FEATURE_LEFT_ICON);
        WindowManager.LayoutParams lp = dialog1.getWindow().getAttributes();
        lp.dimAmount = 0.5f;
        dialog1.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 
        dialog1.setCancelable(true);
        dialog1.setContentView(R.layout.alert_dialog);
        dialog1.show();
        dialog1.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.lemon1_fw);

I have tried some comments found online and seems there is no difference to put setFeatureDrawableResource either before or after .show() ; 我已经尝试了一些在网上找到的评论,似乎在.show()之前或之后放置setFeatureDrawableResource没什么区别;

How could it be solved? 怎么解决呢? many thanks!! 非常感谢!!

this is a simple sample for getting custom layout for dialog 这是获取对话框自定义布局的简单示例

private Dialog m_ShowAction;
//in onCreate
m_ShowAction = new Dialog(Contacts_List_Activity.this);
m_ShowAction.requestWindowFeature(Window.FEATURE_NO_TITLE);
m_ShowAction.setContentView(R.layout.popup_action_dialog);
m_ShowAction.setCanceledOnTouchOutside(true);
......

//inflate your control on custom Dialog layout like this
ListView lstActionList = (ListView) m_ShowAction.findViewById(R.id.listView1);

and you can set onclick or anything for any control on custom layout like the normal activity layout 并且您可以为自定义布局(如常规活动布局)上的任何控件设置onclick或其他任何内容

at the end call m_ShowAction.show(); 最后调用m_ShowAction.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM