android使用xml布局文件设计提示对话框
1. prompt_layout.xml文件[html]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/promptmessage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="Your text goes here"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText_prompt"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
2. java文件
[java]
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.prompt_layout, null);
//get a builder and set the view
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Prompt");
builder.setView(view);
builder.setPositiveButton("确定",null);
builder.setNegativeButton("取消",null);
builder.create();
builder.show();
3. 效果图
摘自 Snowball
补充:移动开发 , Android ,