Android 如何在对话框中显示带标题的图标
我在我的代码中使用一个带有自定义布局的对话框Android 如何在对话框中显示带标题的图标,android,Android,我在我的代码中使用一个带有自定义布局的对话框 问题是我对如何显示带有标题的图标感到困惑 我没有使用警报对话框:我使用的是对话框。 下面是我的代码。 当我使用这条线时: // dialog2.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher); 应用程序崩溃了 dialog2 = new Dialog(context); View vLoad = LayoutInflater.fro
问题是我对如何显示带有标题的图标感到困惑 我没有使用警报对话框:我使用的是对话框。
下面是我的代码。
当我使用这条线时:
// 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>
dialog2=新建对话框(上下文);
View vLoad=LAYOUTINGFLATER.from(ActivityHome.this)。充气(
R.layout.timer,空);
对话框2.setContentView(vLoad);
TextView text1=(TextView)对话框2.findViewById(R.id.text1);
TextView text2=(TextView)dialog2.findViewById(R.id.text2);
按钮关闭dailog=(按钮)对话框2.findViewById(R.id.dailogexit);
String next=“红色”;
字符串[]documentlisencearray=documentlisence.split(“,”);
if(documentlisencearray[1]!=null)
{String newString1=新字符串(documentlisencearray[1].toString());
字符串[]documentobject=newString1.split(“”);
text1.setText(documentobject[0]);
text2.setText(documentobject[1]);
}
对话框2.setTitle(“文件到期警报”);
对话框2.setTitle(Html.fromHtml(“文档到期警报”);
//对话框2.setFeatureDrawableResource(Window.FEATURE\u LEFT\u图标,R.drawable.ic\u启动器);
对话框2.可设置可取消(false);
dialog2.show();
setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
//
对话2.解散();
}
});
}
这是我的xml///timer.xml///
以下是解决方案
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();
您需要在对话框中使用此选项
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)
但如果您使用的是
自定义xml
文件,则在该文件中为图像视图设置图标;我想显示此文本的图标lwft,以便您可以调用dialog.setIcon(R.drawable.ic_launcher)代码>我更新我的XMLUR代码对话框.setIcon(R.drawable.ic_启动器);show error那一行出现了什么错误?你的代码dialog.setFeature导致com.android.internal.policy.impl.PhoneWindow.getDrawableState(PhoneWindow.java:3023)上的应用程序出现错误崩溃,这一行的工作是dialog.requestWindowFeature(Window.FEATURE\u LEFT\u图标);什么意思b this line Window.FEATURE_LEFT_ICONIt表示在标题栏的左侧有一个图标的标志