我想创建一个自定义AlertDialog
,我将Layout
设为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/appbg">
<LinearLayout
android:id="@+id/title_template"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@drawable/alert_bg">
<ImageView
android:id="@+id/titleIcon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="top"
android:layout_marginLeft="6dp"
android:paddingRight="10dip"
android:paddingTop="6dip"
android:src="@drawable/warning"
android:contentDescription="@string/image"/>
<TextView
android:id="@+id/alertTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:textStyle="bold" />
</LinearLayout>
<ImageView android:id="@+id/titleDivider"
android:layout_width="fill_parent"
android:layout_height="5dip"
android:scaleType="fitXY"
android:gravity="fill_horizontal"
android:src="@drawable/divider"
android:contentDescription="@string/image"/>
</LinearLayout>
自定义AlertDialog
的类是:
public class Alert extends Builder {
protected final Context context;
protected TextView mTitle = null;
protected ImageView mIcon = null;
public Alert(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.context = context;
View custonTitle = View.inflate(context, R.layout.alert_title, null);
mTitle = (TextView) custonTitle.findViewById(R.id.alertTitle);
mIcon = (ImageView) custonTitle.findViewById(R.id.titleIcon);
setCustomTitle(custonTitle);
}
@Override
public Alert setIcon(Drawable icon) {
// TODO Auto-generated method stub
mIcon.setImageDrawable(icon);
return this;
}
@Override
public Alert setIcon(int iconId) {
// TODO Auto-generated method stub
mIcon.setImageResource(iconId);
return this;
}
@Override
public Alert setTitle(CharSequence title) {
// TODO Auto-generated method stub
mTitle.setText(title);
return this;
}
@Override
public Alert setTitle(int titleId) {
// TODO Auto-generated method stub
mTitle.setText(titleId);
return this;
}
}
PROBLEM
我无法获得正确的Dialog外观,它让我看起来像:
我希望它出现在Not Here
的地方..默认消息背景不会出现...
答案 0 :(得分:0)