前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >011android初级篇之android登录界面的设计

011android初级篇之android登录界面的设计

作者头像
上善若水.夏
发布2018-09-28 10:36:28
2.6K0
发布2018-09-28 10:36:28
举报
文章被收录于专栏:上善若水上善若水

设计目标

  1. 密码账户的输入
  2. 输入账户时,自动显示匹配账户
  3. 没有帐号,显示官网超链接

登录框的自动提示功能参考一下链接中的AutoCompleteTextView的使用

布局文件

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_login">


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="15dip"
        android:layout_margin="15dip"
        android:background="@drawable/background_login_div">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="5dp"
            android:text="@string/login_label_username"
            android:id="@+id/login_user_input"
            />
        <EditText
            android:id="@+id/username_edit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/login_username_hint"
            android:layout_below="@+id/login_user_input"
            android:singleLine="true"
            android:inputType="text"
            />

        <TextView
            android:id="@+id/login_passwd_input"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/username_edit"
            android:layout_marginTop="3dp"
            android:text="@string/login_label_passwd"/>
        <EditText
            android:id="@+id/passwd_edit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/login_passwd_input"
            android:password="true"
            android:singleLine="true"
            android:inputType="textPassword"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login_button"
            android:layout_below="@id/passwd_edit"
            android:layout_alignRight="@id/passwd_edit"
            android:text="@string/login_label_signin"
            />
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/infoWords"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/login_register_link"
            android:layout_marginLeft="15dp"
            android:textColor="#888"
            android:textColorLink="#FF0066CC"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/cat"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_marginRight="25dp"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="25dp"
            android:id="@+id/logo"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo"
            android:layout_toLeftOf="@id/logo"
            android:layout_alignBottom="@id/logo"
            android:layout_marginBottom="25dp"
            />

    </RelativeLayout>
</LinearLayout>

编程代码

代码语言:javascript
复制
public class LoginActivity extends Activity {
    private static final String TAG = "LoginActivity" ;

    Button loginButton;
    EditText username_edit;
    EditText passwd_edit;
    TextView infoWords;
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.login);

        username_edit = (EditText)findViewById(R.id.username_edit);
        passwd_edit  =  (EditText)findViewById(R.id.passwd_edit);
        infoWords    = (TextView)findViewById(R.id.infoWords);
        infoWords.setMovementMethod(LinkMovementMethod.getInstance());

        loginButton =(Button) findViewById(R.id.login_button);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user=username_edit.getText().toString().trim();
                String passwd=passwd_edit.getText().toString().trim();
                if(checkAcount(user,passwd)){
                    setResult(RESULT_OK);
                    finish();
                }
                else {
                    Toast.makeText(LoginActivity.this, "用户名密码不正确,请重新输入!", Toast.LENGTH_LONG).show();
                }

            }
        });
    }

    boolean checkAcount(String user,String passwd){
        // TODO: 2015/11/9
        Log.w(TAG,"checkAcconut "+user + passwd);
        if(user == "test" && passwd == user){
            return true;
        }
        return false;
    }
}

在TextView中设置超链接

有两种方式

第一种

代码语言:javascript
复制
<string name="login_register_link">没有帐号,<a href='http://www.jianshu.com/users/2097e21ffc33/latest_articles'>注册</a></string>

<TextView
    android:id="@+id/infoWords"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/login_register_link"
    android:layout_marginLeft="15dp"
    android:textColor="#888"
    android:textColorLink="#FF0066CC"/>

textView.setMovementMethod(LinkMovementMethod.getInstance()); 

第二种

代码语言:javascript
复制
String html = "有问题:\n"; 
html+="www.baidu.com";//这里即使不加协议好HTTP;也能自动被系统识别出来。 
textView.setText(html); 
textView.setAutoLinkMask(Linkify.ALL); 
textView.setMovementMethod(LinkMovementMethod.getInstance()); 

参考链接

  1. Android精美登录界面设计
  2. Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)
  3. Android实现登录界面和功能实例
  4. AutoCompleteTextView
  5. 010android初级篇之Activity的返回值
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015.11.09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 设计目标
  • 布局文件
  • 编程代码
  • 在TextView中设置超链接
  • 参考链接
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档