天天看點

21. android dialog——自定義對話框之二

先建立一個layout,命名為customer_dialog.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:paddingRight="10dip"

android:paddingLeft="10dip">

<TextView android:id="@+id/userNameText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="18dip"

android:text="使用者名:"

android:paddingRight="10dip"

/>

<EditText android:id="@+id/userNameEditText"

android:text="輸入使用者名"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:lines="1"

/>

</LinearLayout>

然後在昨天的android dialog——自定義對話框之一 的修改onCreate方法,修改如下:

@Override

protected void onCreate(Bundle savedInstanceState) {

//關于LayoutInflate詳解

//http://blog.csdn.net/jamesliulyc/archive/2011/04/14/6324432.aspx

LayoutInflater inflater = LayoutInflater.from(context);

View customerLayout =

inflater.inflate(R.layout.customer_dialog, null);

setView(customerLayout);

super.onCreate(savedInstanceState);

}

關于LayoutInflate詳解, 請參照 android Tab 頁籤控件 裡的注釋

以上就是在昨天的基礎之上增加的自定義xml,其他任何代碼都不用動了,很簡單,接下來将繼續添加事件監聽

還是來個效果圖吧,貌似比昨天的漂亮一點:

21. android dialog——自定義對話框之二