1、构建原始工程
2、配置git
2.1 gitee上新建工程
2.2 代码初始化仓库
git init
git remote add origin https://gitee.com/Arikes_admin/media-tool.git
git add .
git commit -m "first commit"
git push --set-upstream origin master
3、修改代码主Activity基类
4、页面添加按钮测试
4.1 修改工程资源管理器试图为工程模式【此模式与文件目录一致,方便】
4.2 修改主Activity的基类布局控件为相对布局控件 RelativeLayout,并添加按钮
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_test"
android:text="测试按钮"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
4.3 MainActivity.java中添加按钮点击事件
package com.kkstudio.media;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public Button mBtnTest = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUI();
}
/**
* 初始化页面UI
* */
private void initUI() {
mBtnTest = (Button)findViewById(R.id.btn_test);
mBtnTest.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.btn_test:
ShowToast("测试按钮被点击了");
break;
}
}
/**
* 展示Toast提示
* */
private void ShowToast(String msg) {
Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
}
}
5、虚拟机运行程序
5.1 创建虚拟手机或者真机运行
5.2 运行