之前的文章已经讲解了Android Studio的安装和配置过程
请参考:Android Studio 安装配置完整教程【小白一看就会】
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout 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"
- android:orientation="vertical"
- tools:context=".MainActivity">
- </LinearLayout>
-
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout 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"
- android:orientation="vertical"
- tools:context=".MainActivity">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="学习安卓,你准备好了吗"
- android:id="@+id/tv_android"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="准备好了"
- android:id="@+id/bt_android"
- android:onClick="Welcome"/>
- </LinearLayout>
-
注:小白为了养成良好习惯,每个控件的id一定要起得严谨,一看到就知道是什么意思,最好不要含有数字。
- public class MainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void Welcome(View view) {
- Toast.makeText(this, "欢迎来到安卓世界", Toast.LENGTH_SHORT).show();
- }
- }
-
注:setContentView(R.layout.activity_main);这句话是布局绑定
可能有许多小伙伴不知道R是什么?
R是类 索引类 把r文件下的所有文件进行索引 资源目录的索引
通过索引号找到响应的静态成员