学习基础开发技能_Android
20240207,
1.日志
Log.d("ning", "onCreate");
2.win11开启android虚拟化支持
勾选这俩:参考 https://zhuanlan.zhihu.com/p/658580570
3.运行app指的是运行某个模块,而非运行某个项目
4.app工程分为两个层次,一个是项目,一个是模块。
5.模块依附于项目,一个项目至少有一个模块,一个项目可以有多个模块。
6.我们所说的“编译运行app”,指的是运行某个模块,而不是整个项目,因为模块才对应于实际app。
20240209,
1.android studio里Ctrl+shift+o自动组织导入
2.activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello world!"/> </LinearLayout>
3.MainActivity.java
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = findViewById(R.id.tv); tv.setText("你好,世界!"); } }
20240210,
1.activity_main2.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Activity main 2 by manual creation"/> </LinearLayout>
2.activity_main3.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="activity main 3 by create empty activity"/> </LinearLayout>
3.activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello world!"/> <Button android:id="@+id/buttonManual" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转(通过手动创建的)MainActivity2"/> <Button android:id="@+id/buttonMenu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转(通过empty activity菜单创建的)MainActivity3"/> </LinearLayout>
4.MainActivity2.java
public class MainActivity2 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); } }
5.MainActivity3.java
public class MainActivity3 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); } }
6.AndroidManifest.xml
<activity android:name=".MainActivity3"/> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity2" />
7.MainActivity.java
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = findViewById(R.id.tv); tv.setText("你好,世界!"); Button buttonManual = findViewById(R.id.buttonManual); buttonManual.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setClass(MainActivity.this, MainActivity2.class); startActivity(intent); } }); Button buttonMemu = findViewById(R.id.buttonMenu); buttonMemu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setClass(MainActivity.this, MainActivity3.class); startActivity(intent); } }); } }
8,