ANDROID第一个UI界面学---登录到对话框

   一开始布局就再login_dlg.xml文件中拖了两个文本框,两个编辑框,两个按钮,此处学校到对于布局是属性中如果前面有layout的就是表示该控件和父控件到关系,如果没有到就表示该控件到子控件和该控件到关系。后来发现按钮可以直接使用对话框上到就行了

然后就开始着手把它放到对话框上。说实话,以前没使用过JAVA,怎么创建对话框都不知道,真够呛的。

其实我也并不是没有头绪,因为我知道,再android到SDK自带了很多源码,不会再里面看看就知道了。再SDK中到ApiDemos工程下面,各种控件到效果,实现代码都是有到。我到登录对话框代码就是再哪里找到的,你说难不难。


下面是从API Demos下面拷贝过来一段代码放到我到工程中,主要就是对对话框到onCreateDialog进行重写。

public class HelloWorld extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        showDialog(1);
        
         
    }

    @Override
    protected Dialog onCreateDialog(int id) {
         LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.login_dlg, null);
            return new AlertDialog.Builder(HelloWorld.this)
                .setIcon(R.drawable.icon)
                .setTitle(R.string.land_dialog_title)
                .setView(textEntryView)
                .setPositiveButton(R.string.land_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        //处理登录
                        Toast.makeText(HelloWorld.this,getText(R.string.land_select_ok), Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton(R.string.land_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        //处理取消登录
                        Toast.makeText(HelloWorld.this,getText(R.string.land_select_cancel), Toast.LENGTH_SHORT).show();
                    }
                })
                .create();
    }
}


下面是我到login_dlg.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"
    >
<TextView  
    android:id="@+id/username"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:textColor="#ff0000"    
    android:gravity="left"
    android:text="用户名:"
    />
<EditText  
    android:id="@+id/txt_username"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:gravity="fill_horizontal"
    android:autoText="false"
    android:capitalize="none"
    android:text="请输入用户名"
    />
<TextView  
    android:id="@+id/password"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:textColor="#ff0000"    
    android:gravity="left"
    android:text="密码:"
    />
<EditText  
    android:id="@+id/txt_password"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:gravity="fill_horizontal"
    android:autoText="false"
    android:password="true"
    android:capitalize="none"
    android:text="请输入密码"
    />
</LinearLayout>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值