1.安裝集成開發環境android
根據華為老師提供的博客進行android環境安裝,
從官網中下載Android studio安裝包,再去下載jdk.
安裝包盡量放在d盤,跟著步驟,最后彈出

開始做第一個hello word程式,先創建一個空的模板,再next,創建hello world ,finish完成創建,

1.了解AndroidStudio
-
1.了解AndroidStudio的結構
-
2.java目錄 存放java源代碼
-
4.res目錄 是這個app的資源
-
5.drawable存放圖片資源
-
6.layout存放布局檔案資源
-
7.mipmap存放啟動的圖示資源
-
8.values存放常量資源 (有顏色、字串、樣式)
如圖所示:

注意要在android模式下進行
3.實作登錄界面
創建一個新的空的模板,再java的檔案夾中,創建一個新的名叫nextactivity.java,在里面實作登錄的功能,
package com.example.login;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class nextActivity extends AppCompatActivity {
private Button Btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
EditText Et1 = findViewById(R.id.et_1);
Drawable icon = getResources().getDrawable(R.drawable.ic_launcher_background);
icon.setBounds(0,0,44,44);
Et1.setCompoundDrawables(icon, null, null, null);
EditText Et2 = findViewById(R.id.et_2);
Drawable password = getResources().getDrawable(R.drawable.ic_launcher_foreground);
password.setBounds(0,0,44,44);
Et2.setCompoundDrawables(password,null,null,null);
Btn1 = findViewById(R.id.btn_1);
Btn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Toast.makeText(nextActivity.this,"Login failed",Toast.LENGTH_SHORT).show();
}
});
}
}
在res/layout/new,選擇xml中的llayout xml file,創建成功,

設定登錄界面的布局代碼如下:
package com.example.login;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class nextActivity extends AppCompatActivity {
private Button Btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
EditText Et1 = findViewById(R.id.et_1);
Drawable icon = getResources().getDrawable(R.drawable.ic_launcher_background);
icon.setBounds(0,0,44,44);
Et1.setCompoundDrawables(icon, null, null, null);
EditText Et2 = findViewById(R.id.et_2);
Drawable password = getResources().getDrawable(R.drawable.ic_launcher_foreground);
password.setBounds(0,0,44,44);
Et2.setCompoundDrawables(password,null,null,null);
Btn1 = findViewById(R.id.btn_1);
Btn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Toast.makeText(nextActivity.this,"Login failed",Toast.LENGTH_SHORT).show();
}
});
}
}
在右上角點擊綠色的三角形進行運行

出現問題,代碼沒有出錯,可運行登錄界面顯示不出來,如圖是設計界面,一到手機運行模擬便彈不出來,目前問題還在解決中,

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/246580.html
標籤:其他
下一篇:Android學習筆記
