我在代码中使用自定义布局的对话框;
问题是我对如何显示带标题的图标感到困惑。
我没有使用警告对话框:我正在使用对话框 以下是我的代码 当我使用这一行时:
// dialog2.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
应用程序崩溃
dialog2 = new Dialog(context);
View vLoad = LayoutInflater.from(ActivityHome.this).inflate(
R.layout.timer, null);
dialog2.setContentView(vLoad);
TextView text1 = (TextView) dialog2.findViewById(R.id.text1);
TextView text2 = (TextView) dialog2.findViewById(R.id.text2);
Button closedailog = (Button) dialog2.findViewById(R.id.dailogexit);
String next = "<font color='#EE0000'>red</font>";
String[] documentlisencearray = documentlisence.split(",");
if(documentlisencearray[1]!=null)
{String newString1 = new String(documentlisencearray[1].toString());
String[] documentobject = newString1.split("=");
text1.setText(documentobject[0]);
text2.setText(documentobject[1]);
}
dialog2.setTitle("Documents Due Alert");
dialog2.setTitle( Html.fromHtml("<font color='#ff0000'>Documents Due Alert</font>"));
// dialog2.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
dialog2.setCancelable(false);
dialog2.show();
closedailog.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//
dialog2.dismiss();
}
});
}
this is my xml///timer.xml///
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:id="@+id/layouttimer">
<TextView
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<TextView
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<TextView
android:id="@+id/text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<TextView
android:id="@+id/text4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<TextView
android:id="@+id/text5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<TextView
android:id="@+id/text6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<Button
android:id="@+id/dailogexit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:text="OK " >
</Button>
</LinearLayout>
答案 0 :(得分:1)
这是解决方案
final Dialog dialog = new Dialog(this);
**dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);**
dialog.setTitle(R.string.my_dialog_title);
dialog.setContentView(R.layout.my_dialog_layout);
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.some_icon);
dialog.show();
答案 1 :(得分:1)
您需要将此用于对话
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.yourlayoutfile);
dialog2.setTitle("Documents Due Alert");
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.your_icon)