简体   繁体   中英

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() ;

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

at the end call m_ShowAction.show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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