[英]How to set Title,Icon for custom dialog in android
I've a class which extends Dialog in android.It shows custom dialog well.But i couldn't set icon & title for that dialog.How could i do that? 我有一个在android中扩展Dialog的类。它很好地显示了自定义对话框。但是我无法为该对话框设置图标和标题,我该怎么做?
My code: 我的代码:
public class helpDialog extends Dialog implements OnClickListener {
Button okButton;
String Description;
TextView text;
public helpDialog(Context context, String desc) {
super(context);
Description=desc;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
/** Design the dialog in main.xml file */
setContentView(R.layout.custom);
text=(TextView)findViewById(R.id.text);
text.setText(Description);
okButton = (Button) findViewById(R.id.submit);
okButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
/** When OK Button is clicked, dismiss the dialog */
if (v == okButton)
dismiss();
}
}
My custom.xml: 我的custom.xml:
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textColor="#000000"
android:gravity="center"
android:text="Help alert for iDispatch"
android:textSize="18dp" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:textColor="#FFFFFF" />
USE THIS ONE 使用这个
private AlertDialog AskOption()
{
AlertDialog myQuittingDialogBox =new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle("Confirm Delete")
.setMessage("Do you want to Delete Employee "+listview_array[1]+" ?")
.setIcon(R.drawable.dialog_warning)
.setPositiveButton(resource.getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{
if(dh.selectEmployeeTypeById(EmpId).size()>0)
{
//CODE
}
dialog.dismiss();
}
})
.setNegativeButton(resource.getString(R.string.no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create();
return myQuittingDialogBox;
}
for custom dialog a small example layout this is my custom dialog 对于自定义对话框一个小的示例布局,这是我的自定义对话框
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".StaffTimeClock" >
<TextView android:id="@+id/img"
android:layout_width="fill_parent"
android:text="@string/selectjob"
android:gravity="center"
android:textSize="30dp"
android:textColor="#fff"
android:background="#203C56"
android:padding="10dp"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:cacheColorHint="#222000" />
<View
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#000"/>
<LinearLayout android:id="@+id/lin00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="horizontal">
<Button
android:layout_weight="0.1"
android:contentDescription="@string/ok"
android:id="@+id/okBtn"
android:layout_gravity="center"
android:layout_margin="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="@drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ok"/>
<Button
android:layout_weight="0.1"
android:contentDescription="@string/ok"
android:id="@+id/selectBtn"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="@drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/selectall"/>
<Button
android:layout_weight="0.1"
android:contentDescription="@string/cancel"
android:id="@+id/cancelBtn"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="@drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"/>
</LinearLayout>
</LinearLayout>
this is the code call the dialog box 这是代码调用对话框
private void showPopUp(int eid)
{
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("");
LayoutInflater inflater = getLayoutInflater();
final View PopupLayout = inflater.inflate(R.layout.jobselection, null);
helpBuilder.setView(PopupLayout);
final AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
okbtn = (Button)PopupLayout.findViewById(R.id.okBtn);
caneclbtn = (Button)PopupLayout.findViewById(R.id.cancelBtn);
selectallbtn = (Button)PopupLayout.findViewById(R.id.selectBtn);
clearallbtn = (Button)PopupLayout.findViewById(R.id.clearallBtn);
jobList = (ListView)PopupLayout.findViewById(R.id.list);
mylist = new ArrayList<HashMap<String, String>>();
for(int i=0;i<Punchedjobs.size();i++)
{
map = new HashMap<String, String>();
map.put("name", Punchedjobs.get(i));
mylist.add(map);
}
sd = new SimpleAdapter(StaffTimeClock.this,mylist,R.layout.jobslist,
new String[]{"name"},new int[]{R.id.jobText});
jobList.setAdapter(sd);
okbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
\\code
}
});
caneclbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
helpDialog.dismiss();
}
});
selectallbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
}
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.