目录
三、创建Fragment(eg:fragment_chat)
6、hidefragment():令未被选中的三个选项区恢复默认
一、设计界面:top.xml
设计中发现界面上方有一个自带的标题框,需要在app/java/MainActivity中onCreat函数中添加如下代码去除:
if (getSupportActionBar()!=null)
{
getSupportActionBar().hide();
}
去除自带的标题框后,设计效果及代码如下:
<?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="65dp"
android:gravity="center"
android:background="#000000"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="WeChat"
android:textColor="#ffffff"
android:textSize="40sp"/>
</LinearLayout>
二、设计界面:bottom.xml
此处以chat为例,设计效果代码如下:
<LinearLayout
android:id="@+id/tab_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="bottom">
<ImageButton
android:id="@+id/imageButton_chat"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#ffffff"
android:src="@drawable/icon_chat"
android:clickable="false"
/>
<TextView
android:id="@+id/textView2_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:saveEnabled="false"
android:text="chat"
android:textColor="#000000"
android:textSize="15sp" />
</LinearLayout>
其中,bottom.xml文件中:android:clickable="false"这句是为了将图标和图标下方的字体在点击触发时捆绑。
三、创建Fragment(eg:fragment_chat)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/id_chat"
tools:context=".Fragment_chat">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:saveEnabled="false"