欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)簡(jiǎn)潔的APP登錄界面

 更新時(shí)間:2021年01月27日 10:24:30   作者:安小松丶  
這篇文章主要為大家詳細(xì)介紹了Android簡(jiǎn)潔登錄界面的編寫代碼,實(shí)現(xiàn)簡(jiǎn)單的登錄,用戶名密碼驗(yàn)證功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

今天需求要做一個(gè)所有app都有的登錄界面,正好鞏固一下我們之前學(xué)的基礎(chǔ)布局知識(shí)。

先來(lái)看下效果圖

1.布局的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#2197db"
 >
 <ImageView
  android:id="@+id/loginbutton"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_marginTop="40dp"
  android:src="@drawable/login_pic"/>
 
<LinearLayout
  android:id="@+id/input"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@+id/loginbutton"
  android:layout_marginLeft="28dp"
  android:layout_marginRight="28dp"
  android:background="#fff"
  android:orientation="vertical">
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="44dp"
  android:background="#fff"
  android:gravity="center_vertical"
  android:orientation="horizontal" >

 <EditText
   android:id="@+id/userId"
   android:layout_width="wrap_content"
   android:layout_height="fill_parent"
   android:layout_weight="1"
   android:background="@null"
   android:imeOptions="actionDone"
   android:textSize="16sp"
   android:ems="10"
   android:hint="請(qǐng)輸入用戶名"
   >
 </EditText>
<Button
   android:id="@+id/button_bar"
   android:layout_width="20dp"
   android:layout_height="20dp"
   android:layout_marginRight="8dp"
   android:layout_marginLeft="1dp"
   android:background="@drawable/login_input_arrow"
   />

 </LinearLayout>
 <View
   android:layout_width="fill_parent"
   android:layout_height="1.0px"
   android:layout_marginLeft="1.0px"
   android:layout_marginRight="1.0px"
   android:background="#ffc0c3c4" />
<EditText
   android:id="@+id/pass"
   android:layout_width="fill_parent"
   android:layout_height="44.0dip"
   android:background="#00ffffff"
   android:gravity="center_vertical"
   android:inputType="textPassword"
   android:maxLength="16"
   android:maxLines="1"
   android:textColor="#ff1d1d1d"
   android:textColorHint="#ff666666"
   android:textSize="16.0sp"
   android:hint="請(qǐng)輸入密碼"
   />
 </LinearLayout>
 <Button
  android:id="@+id/loginBtn"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_below="@+id/input"
  android:layout_marginTop="10dp"
  android:background="#3aadfd"
  android:text="登 錄"
  android:textColor="#ffffff"
  android:textSize="18dp"
  android:layout_centerHorizontal="true"
  android:layout_marginLeft="28dp"
  android:layout_marginRight="28dp"/>
 <TextView
  android:text=""
  android:layout_width="wrap_content"
  android:layout_below="@+id/loginBtn"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:id="@+id/promptText"
  android:textColor="#ff0000"
  android:layout_marginTop="10dp"
  android:textSize="18sp"/>

</RelativeLayout>

2.java部分代碼

public class LoginActivity extends Activity implements View.OnClickListener{
  private static final String TAG = "login";
   Button loginBtn = null;
   EditText useridEt = null;
   EditText passEt = null;
   TextView promptText = null;
   @Override
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_login);
  loginBtn = (Button) findViewById(R.id.loginBtn);
  loginBtn.setOnClickListener(this);
  useridEt = (EditText) findViewById(R.id.userId); 
  passEt = (EditText) findViewById(R.id.pass);
  promptText = (TextView) findViewById(R.id.promptText);
  OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .connectTimeout(10000L, TimeUnit.MILLISECONDS)
    .readTimeout(10000L, TimeUnit.MILLISECONDS)
    .build();
  OkHttpUtils.initClient(okHttpClient);

 @Override
 public void onClick(View v) {
  String userid = useridEt.getText().toString().trim();
  String pass = passEt.getText().toString().trim();
  if(userid.equals("")){
   promptText.setText(R.string.userIdError);
   return ;
  }
  if(pass.equals("")){
   promptText.setText(R.string.passError);
   return ;
  }
 WebConstant.digest = ("Basic " + new String(Base64.encode((userid + ':' + pass).getBytes(), Base64.DEFAULT))).replace("\n", "");

   String url = WebConstant.REQUESTPATH+"/users/" + userid+"?getAll=true";
   OkHttpUtils.get()
     .url(url).addHeader("Authorization", WebConstant.digest).addHeader("Accept-Language","zh-CN")
     .build().execute(new Callback()
     {
      @Override
      public String parseNetworkResponse(Response response, int id) throws Exception {
       String string = response.body().string();
       JSONObject jsonObj = new JSONObject(string);
       if(jsonObj.get("userName")!=null){
        WebConstant.userId = (String)jsonObj.get("userId");
        WebConstant.userName = (String)jsonObj.get("userName");
        return (String) jsonObj.get("userName");
       }
       return null;
      }

      @Override
      public void onError(Call call, Exception e, int id) {
       WebConstant.digest = null;
       promptText.setText(R.string.loginError);
       Log.i(TAG,e.getMessage());
       e.printStackTrace();
      }

      @Override
      public void onResponse(Object response, int id) {
       promptText.setText(R.string.loginSuccess+" "+response);
       Intent intent = new Intent();
       LoginActivity.this.setResult(WebConstant.RESULT_OK, intent);
       LoginActivity.this.finish();
      }
     });

 }
}  

簡(jiǎn)單的登錄,用戶名密碼驗(yàn)證。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android中使用Service實(shí)現(xiàn)后臺(tái)發(fā)送郵件功能實(shí)例

    Android中使用Service實(shí)現(xiàn)后臺(tái)發(fā)送郵件功能實(shí)例

    這篇文章主要介紹了Android中使用Service實(shí)現(xiàn)后臺(tái)發(fā)送郵件功能的方法,結(jié)合實(shí)例形式分析了Service實(shí)現(xiàn)郵件的發(fā)送、接收及權(quán)限控制相關(guān)技巧,需要的朋友可以參考下
    2016-01-01
  • Android實(shí)現(xiàn)頂部懸浮效果

    Android實(shí)現(xiàn)頂部懸浮效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)頂部懸浮效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android實(shí)現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單)詳解

    Android實(shí)現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單)詳解

    相信大家經(jīng)常在應(yīng)用中會(huì)看到衛(wèi)星菜單,那么這篇文章就來(lái)介紹在Android中如何實(shí)現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單),有需要的可以參考學(xué)習(xí)。
    2016-08-08
  • kotlin $ 字符串模版的使用詳解

    kotlin $ 字符串模版的使用詳解

    $ 在kotlin 中當(dāng)做字符串模版使用,作用就是在字符串里面識(shí)別自己定義的字符,這篇文章主要介紹了kotlin $ 字符串模版的使用,需要的朋友可以參考下
    2024-01-01
  • Android中Socket大文件斷點(diǎn)上傳示例

    Android中Socket大文件斷點(diǎn)上傳示例

    本篇文章主要介紹了Android中Socket大文件斷點(diǎn)上傳示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • Android仿微信雷達(dá)輻射搜索好友(邏輯清晰實(shí)現(xiàn)簡(jiǎn)單)

    Android仿微信雷達(dá)輻射搜索好友(邏輯清晰實(shí)現(xiàn)簡(jiǎn)單)

    仿微信雷達(dá)掃描,仿安卓微信、云播雷達(dá)掃描動(dòng)畫效果點(diǎn)擊中間的黑色圓圈開始掃描動(dòng)畫,再次點(diǎn)擊復(fù)位,需要這種效果的朋友可以自己下載看一下
    2016-02-02
  • Android用文件存儲(chǔ)數(shù)據(jù)的方法

    Android用文件存儲(chǔ)數(shù)據(jù)的方法

    這篇文章主要為大家詳細(xì)介紹了Android用文件存儲(chǔ)數(shù)據(jù)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android Support Palette使用詳解

    Android Support Palette使用詳解

    這篇文章主要介紹了Android Support Palette使用詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • 總結(jié)Android中MD風(fēng)格相關(guān)控件

    總結(jié)Android中MD風(fēng)格相關(guān)控件

    自Android5.0發(fā)布以來(lái),谷歌推出全新的Material Desigen設(shè)計(jì)風(fēng)格,時(shí)過(guò)一年多了,在國(guó)內(nèi)也看到很多應(yīng)用在慢慢適應(yīng)MD設(shè)計(jì)風(fēng)格。今天小編給大家總結(jié)下Android中MD風(fēng)格相關(guān)控件的知識(shí),有需要的可以參考學(xué)習(xí)。
    2016-08-08
  • android實(shí)現(xiàn)多點(diǎn)觸摸應(yīng)用

    android實(shí)現(xiàn)多點(diǎn)觸摸應(yīng)用

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)多點(diǎn)觸摸應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05

最新評(píng)論