21. android dialog——自定义对话框之二

    技术2022-05-18  45

    先建立一个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,其他任何代码都不用动了,很简单,接下来将继续添加事件监听

    还是来个效果图吧,貌似比昨天的漂亮一点:

     

     

     

     


    最新回复(0)