android界面底部BottomBar以及fragment
来源:互联网 发布:复杂网络 机器人定位 编辑:程序博客网 时间:2024/06/06 04:45
推荐一个介绍fragment的好博客
BottomBar开源地址
一个非常完善的Fragment的开源地址,很少在github上看到这么完善的来自天朝的代码。
使用Fragment的原因是要一个漂亮的底栏,可以根据点击的按钮不同加载不同的fragment,这个应该就是但activity对多fragment。
以下是具体代码:
1、 bottomBar.xml
<?xml version="1.0" encoding="utf-8"?><tabs> <tab id="@+id/tab_day" icon="@drawable/newspaper48" title="日报" /> <tab id="@+id/tab_exe" icon="@drawable/text48" title="报表" /> <tab id="@+id/tab_pic" icon="@drawable/chart48" title="图标" /> <tab id="@+id/tab_user" icon="@drawable/user48" title="用户" /></tabs>
2、 装bottomBar的relativeLayout的代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <!-- This could be your fragment container, or something --> <RelativeLayout android:id="@+id/contentContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottomBar" /> <com.roughike.bottombar.BottomBar android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" app:bb_tabXmlResource="@xml/bottombar_tabs" /></RelativeLayout>
3、activity_main.xml的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/root_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"> <!-- This could be your fragment container, or something --> <include layout="@layout/toolbar_layout"/> <include layout="@layout/toplayout"/></LinearLayout>
4、main_activity的代码
package com.hb.bottomlast;import android.content.Intent;import android.graphics.Point;import android.os.Bundle;import android.support.annotation.IdRes;import android.support.v4.app.Fragment;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.text.Layout;import android.view.MotionEvent;import android.view.View;import android.widget.Button;import android.widget.ImageButton;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;import com.github.jjobes.slidedatetimepicker.SlideDateTimeListener;import com.github.jjobes.slidedatetimepicker.SlideDateTimePicker;import com.hb.bottomlast.Persion1_fragment;import com.hb.bottomlast.Persion2_fragment;import com.hb.bottomlast.Persion3_fragment;import com.hb.bottomlast.R;import com.roughike.bottombar.BottomBar;import com.roughike.bottombar.OnTabReselectListener;import com.roughike.bottombar.OnTabSelectListener;import java.text.SimpleDateFormat;import java.util.Date;public class MainActivity extends AppCompatActivity{ double nLenStart = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); } final View layout = findViewById(R.id.contentContainer); BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar); bottomBar.setOnTabSelectListener(new OnTabSelectListener() { @Override public void onTabSelected(@IdRes int tabId) { Object ob=null; switch (tabId) { case R.id.tab_day: ob = new Persion1_fragment(); break; case R.id.tab_exe: ob = new Persion2_fragment(); break; case R.id.tab_pic: ob = new Persion3_fragment(); break; case R.id.tab_user: ob = new Persion4_fragment(); break; } getSupportFragmentManager().beginTransaction().replace(R.id.contentContainer,(Fragment) ob).commit(); } }); bottomBar.setOnTabReselectListener(new OnTabReselectListener() { @Override public void onTabReSelected(@IdRes int tabId) { getSupportFragmentManager().beginTransaction().replace(R.id.contentContainer,new Persion1_fragment()).commit(); } }); }}
剩下的别忘了导入
dependencies {
compile ‘com.roughike:bottom-bar:2.0.2’
}
最后还要建立四个fragment一一对应。
0 0
- android界面底部BottomBar以及fragment
- BottomBar之Android底部菜单
- [Android] BottomBar+ViewPager+Fragment实现炫酷的底部导航效果20160523
- BottomBar+ViewPager+Fragment实现炫酷的底部导航效果
- Android 底部导航栏界面(Fragment)
- Android底部导航栏界面(Fragment中嵌套Fragment)
- 【BottomBar】Android炫酷的底部切换效果V2.0
- Android手机UI设计---”知乎“界面外观模仿篇(一)---使用Fragment实现底部导航以及嵌套
- [Android] 使用 Fragment 实现底部 Tab 切换界面
- Android底部Fragment切换
- 炫酷的底部菜单栏BottomBar
- 第三方开源库:BottomBar 底部导航栏
- 第三方开源库:BottomBar 底部导航栏
- Android ViewPager+Fragment超高仿微信主界面(带底部图标切换动画)
- Android底部导航框架(解决fragment界面重现,getActivity空指针)
- Android Fragment实现底部导航
- Android使用fragment底部菜单栏
- Android 底部菜单栏RadioButton+Fragment
- nodejs死亡笔记之实战篇---微信公众号的开发(1)
- TQ2440使用uboot下的命令行进行ftp下载程序到nand flash
- lua正则表达式判断手机号
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- 漫步微积分三十二——两条曲线间的面积
- android界面底部BottomBar以及fragment
- UVA - 11520 - Fill the Square(贪心)
- leetcode Additive Number
- 51nod 1298 圆与三角形(计算几何)
- 微信消息模板的配置
- JAVA 学习模块七: 二维数组
- Java中被搁置的“goto”保留字
- C枚举类型的使用方法
- bzoj 2393(容斥原理)