日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

怎么用Android做登录界面,利用Android怎么制作一个APP登录界面

發布時間:2025/4/16 Android 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 怎么用Android做登录界面,利用Android怎么制作一个APP登录界面 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

利用Android怎么制作一個APP登錄界面

發布時間:2020-12-02 17:09:10

來源:億速云

閱讀:79

作者:Leah

這期內容當中小編將會給大家帶來有關利用Android怎么制作一個APP登錄界面,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

1.布局的xml文件

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#2197db"

>

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"/>

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">

android:layout_width="fill_parent"

android:layout_height="44dp"

android:background="#fff"

android:gravity="center_vertical"

android:orientation="horizontal" >

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="請輸入用戶名"

>

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"

/>

android:layout_width="fill_parent"

android:layout_height="1.0px"

android:layout_marginLeft="1.0px"

android:layout_marginRight="1.0px"

android:background="#ffc0c3c4" />

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="請輸入密碼"

/>

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"/>

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"/>

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();

}

});

}

}

上述就是小編為大家分享的利用Android怎么制作一個APP登錄界面了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。

總結

以上是生活随笔為你收集整理的怎么用Android做登录界面,利用Android怎么制作一个APP登录界面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。