上一节讲的 TabHost、TabWidget、FrameLayout 实现 Tab 标签控件,只能说又臭又长,妈的,我是来开发业务软件的,我不是围着你的几个类玩过来玩过去的。
我们期望能够用更快捷的方式实现我们所需的控件,把更多精力花在业务上。那就用 TabLayout。
第一步、添加引用
在所需 module 的 build.gradle 文件中,dependencies 节添加:implementation 'com.android.support:appcompat-v7:26.1.0'
我这里是 26.1.0 版本,你那可能不是,如果你不知道版本,可以按 Ctrl + Alt + Shift + S,打开对话框中,选择所需 module,切换到 Dependencies 节,右边加号,选择 Library Dependency。搜索一下,就知道你具体是哪个版本了。
第二步、写布局文件
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="基础信息"/>
android:layout_width="wrap_content"
android:layout_heig