FragmentTabHost简单的主流引用
来源:互联网 发布:企业网络建设方案 编辑:程序博客网 时间:2024/06/06 20:46
FragmentTabHost的应用既简单又好用还是不说了看main_activity布局;
<span style="font-size:18px;"> <span style="font-size:18px;"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"></FrameLayout> <android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="60dp"> </android.support.v4.app.FragmentTabHost></span></span>
下面是Activity的代码,只是 最重要的;
<span style="font-size:18px;">package com.example.fragmenttabhost;import android.app.Activity;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentTabHost;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.widget.TabHost;import static android.R.attr.fragment;import static android.R.attr.tag;public class MainActivity extends FragmentActivity { private FragmentTabHost tabhost; private View view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initview(); } private void initview() { //初始化tabhost tabhost = (FragmentTabHost) findViewById(android.R.id.tabhost);// 设置tabhost的 参数。第一个参数是上下文,第二个是碎片管理者,第三个是要操作碎片的位置。 tabhost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent); // 设置取消按钮的分割线 tabhost.getTabWidget().setDividerDrawable(null); // TabHost.TabSpec a = tabhost.newTabSpec("a"); //设置指示器就是按钮的文本 a.setIndicator("主页"); //指示器可以与bundle绑定进行传值 Bundle bundleA= new Bundle(); bundleA.putString("name","主页"); //第一个参数 是a,第二个是碎片,第三个是bundle的 对象 tabhost.addTab(a,Afragment.class,null); TabHost.TabSpec b = tabhost.newTabSpec("b"); b.setIndicator("我的"); Bundle bundleB= new Bundle(); bundleB.putString("ame","你好"); tabhost.addTab(b,Bfragment.class,null); TabHost.TabSpec c= tabhost.newTabSpec("c"); c.setIndicator("附近"); Bundle bundleC= new Bundle(); bundleC.putString("name","我是c"); tabhost.addTab(c,Cfragment.class,null); TabHost.TabSpec d= tabhost.newTabSpec("d"); d.setIndicator("好好"); Bundle bundleD= new Bundle(); bundleD.putString("name","我是c"); tabhost.addTab(d,Dfragment.class,null); }}</span>
<span style="font-size:18px;"></span>
以下是基类;
<span style="font-size:18px;">package com.example.fragmenttabhost;import android.content.Context;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;/** * Created by 孙贝贝 on 2016/9/27. */public abstract class BaseFragment extends Fragment { Context context; public View view; public TextView content; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { setArgs(); return initView(); } public abstract void setArgs(); public View initView(){ view = LayoutInflater.from(context).inflate(R.layout.fragment_content,null); content = (TextView) view.findViewById(R.id.content); initContent(); return view; } public abstract void initContent();}</span>
基类中加载的布局:
<?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">
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
下面是碎片样式:
<span style="font-size:18px;">package com.example.fragmenttabhost;import android.os.Bundle;import android.support.annotation.Nullable;/** * Created by 孙贝贝 on 2016/9/27. */public class Afragment extends BaseFragment{ private String name; @Override public void setArgs() { context = getActivity(); } @Override public void initContent() { content.setText(""); }//// @Override// public void onCreate(@Nullable Bundle savedInstanceState) {// super.onCreate(savedInstanceState);// Bundle bundle = getArguments();// name = (String) bundle.get("name");// }}</span>
完成哈哈
0 0
- FragmentTabHost简单的主流引用
- FragmentTabHost的简单应用
- FragmentTabHost的简单使用
- FragmentTabHost的简单使用
- FragmentTabHost的简单使用
- FragmentTabHost的简单用法
- android FragmentTabHost 的简单使用
- android FragmentTabHost的简单使用
- android FragmentTabHost 的简单使用
- Android-FragmentTabHost的简单使用
- 用FragmentTabHost达到现在市面上的主流导航页面
- 【FragmentTabHost】FragmentTabHost的使用
- FragmentTabHost简单保存状态的方法
- FragmentTabHost简单保存状态的方法
- 一种简单的底部导航fragmentTabhost
- 简单的创建主流框架
- 几个主流网站系统的引用结构图
- FragmentTabHost简单小例子
- C/C++之变长数组(VAL)和可伸缩型数组成员
- Red Hat 系列的Linux环境变量的修改(永久,暂时)
- RequestDispatcher的使用
- 三大基础排序算法java实现
- 购物单
- FragmentTabHost简单的主流引用
- 图片搜索比较
- 利用状态模式CSV文件序列化
- 麦子学院-Web前端开发工程师系列培训教程
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?
- ECharts使用心得总结
- 立体视觉:算法与应用(二)
- 使用weinre在PC端同步远程调试移动端页面(在xampp上部署项目到Tomcat,并通过外网访问(图解). )
- D3_文件操作