我个人觉得这个与fragment4 5是一样的,但是之前有三个项目中就是这样用的,没有出现问题,有必要拿出来分享下。

我的博客
android fragment学习5–fragment扩展 TabLayout非自定义
https://blog.csdn.net/qq_26296197/article/details/81146989

涉及到原项目,就不放图片了。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/main_sildingmenu"xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:background="@android:color/transparent"android:layout_height="match_parent"android:orientation="vertical"><FrameLayout
        android:id="@+id/fragment_tabcontent"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"></FrameLayout><!-- 导航条--><View
        android:layout_width="match_parent"android:layout_height="1dp"android:background="@android:color/darker_gray"/><android.support.v4.app.FragmentTabHost
        android:id="@+id/fragment_tabhost"android:layout_width="match_parent"android:layout_height="56dp"></android.support.v4.app.FragmentTabHost>
</LinearLayout>

这个布局会有警告,可以用这个方法解决(我没有进行优化,警告仍然正常跑项目,现在既然把代码贴上来,把解决办法写下)

<!--定义FragmentTabHost控件--><android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@android:color/black" ><!--装4个Fragment--><FrameLayout
            android:id="@android:id/tabcontent"android:layout_width="0dp"android:layout_height="0dp"android:layout_weight="0" /><!--装Tab的内容--></android.support.v4.app.FragmentTabHost>
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;import com.ainisi.myn.form.R;
import com.ainisi.myn.form.base.App;
import com.ainisi.myn.form.fragment.GroupChatFragment;
import com.ainisi.myn.form.fragment.HomePagerFragment;
import com.ainisi.myn.form.fragment.InfroPagerFragment;
import com.ainisi.myn.form.fragment.PersonalPagerFragment;
import com.ainisi.myn.form.model.AppField;
import com.ainisi.myn.form.model.Friends;
import com.ainisi.myn.form.server.broadcast.BroadcastManager;
import com.ainisi.myn.form.utils.BackGround;
import com.ainisi.myn.form.utils.BadgeUtils;
import com.ainisi.myn.form.utils.GetToken;
import com.ainisi.myn.form.utils.L;
import com.igexin.sdk.PushManager;
import java.util.List;
import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.UserInfo;
import me.leolin.shortcutbadger.ShortcutBadger;public class MainActivity extends AppCompatActivity  {//测试private FragmentTabHost tabHost;private Object token;private List<Friends> userIdList;public TextView tvNum = null;public TextView tvNumInfro ;private static final String TAG = "MainActivity";private Bundle bundle;private long lastClickTime = 0;private String trueName;private String infromation;private String quickName;private String chooseName;private String head;private String choiceHead;public int messageNum;private Boolean isopenPush ;private Intent intent;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();initData();}//咨询消息@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);intentJump(intent);}private void initView() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {Window window = getWindow();// Translucent status barwindow.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}intentJump(null);tabHost = (FragmentTabHost) findViewById(R.id.fragment_tabhost);//关联碎片tabHost.setup(this, getSupportFragmentManager(), R.id.fragment_tabcontent);//添加碎片tabHost.addTab(tabHost.newTabSpec("shouye").setIndicator(getView(0)), HomePagerFragment.class, null);tabHost.addTab(tabHost.newTabSpec("jiedan").setIndicator(getView(1)), PersonalPagerFragment.class, null);tabHost.addTab(tabHost.newTabSpec("pingjia").setIndicator(getView(2)), InfroPagerFragment.class, null);tabHost.addTab(tabHost.newTabSpec("wode").setIndicator(getView(3)), GroupChatFragment.class, null);//去掉间隔图片tabHost.getTabWidget().setDividerDrawable(null);//群聊天if(intent!=null&&intent.getStringExtra("tofeedback")!=null){tabHost.setCurrentTab(3);}//资讯消息if(infromation!=null&&infromation.equals("yes")){tabHost.setCurrentTab(2);}}private void initData() {PushManager.getInstance().initialize(this.getApplicationContext());  //个推//把userToken给后台String loginUrId = App.mCache.getAsString(AppField.loginUserId);if (loginUrId != null) {getToken(loginUrId);}//注册广播.判读网络情况IntentFilter filter = new IntentFilter();filter.addAction(AppField.pushActionHide);filter.addAction(AppField.bgSendMessageAction);filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);filter.addAction(AppField.sendbadgetNum);registerReceiver(receiver, filter);}//得到视图 ,关联对应的tabhostprivate View getView(int position) {View v=null;ImageView tabImg = null;TextView tabText = null;if(position==3){v = LayoutInflater.from(this).inflate(R.layout.layout_tab_feedback, null);tabImg = (ImageView) v.findViewById(R.id.tab_img);tvNum = (TextView) v.findViewById(R.id.iv_num);tabText = (TextView) v.findViewById(R.id.tab_name);} else if(position==2){v = LayoutInflater.from(this).inflate(R.layout.layout_tab_infromation, null);tabImg = (ImageView) v.findViewById(R.id.tab_img);tvNumInfro = (TextView) v.findViewById(R.id.iv_num_infro);tabText = (TextView) v.findViewById(R.id.tab_name);}else {v = LayoutInflater.from(this).inflate(R.layout.layout_tab, null);tabImg = (ImageView) v.findViewById(R.id.tab_img);tabText = (TextView) v.findViewById(R.id.tab_name);}switch (position) {case 0:tabImg.setBackgroundResource(R.drawable.tab_select0);tabText.setText(R.string.homepager);break;case 1:tabImg.setBackgroundResource(R.drawable.tab_select1);tabText.setText(R.string.personal);break;case 2:tabImg.setBackgroundResource(R.drawable.tab_select2);tabText.setText(R.string.consult);break;case 3:tabImg.setBackgroundResource(R.drawable.tab_select3);tabText.setText(R.string.feedback);break;}return v;}}
<?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"android:orientation="vertical"><ImageView
        android:id="@+id/tab_img"android:layout_width="34dp"android:layout_height="34dp"android:layout_gravity="center_horizontal" /><TextView
        android:id="@+id/tab_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:text="12"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_selected="true" android:drawable="@mipmap/icon_home_press"/><item android:state_selected="false" android:drawable="@mipmap/icon_home"/>
</selector>

已经给出主要的代码了,其他的代码就不贴上了。

参考文档
https://developer.android.google.cn/reference/android/support/v4/app/FragmentTabHost

android fragment学习6--FragmentTabHost底部布局相关推荐

  1. android fragment学习4-底部布局扩展TabLayout

    我的博客 Fragment学习3–底部tab布局 https://blog.csdn.net/qq_26296197/article/details/81146319 布局结构 用的是google比较 ...

  2. android Fragment 学习资料推荐

    为什么80%的码农都做不了架构师?>>>    android   Fragment 学习资料推荐:android大神 郭霖 http://blog.csdn.net/guolin_ ...

  3. Fragment学习3--底部tab布局

    我的博客 Fragment学习2–简单的添加Fragment https://blog.csdn.net/qq_26296197/article/details/81146022 MessageFra ...

  4. android应用开发---(第1章)android基础学习之六大Layout布局

    Android中任何可视化的控件都是从android.veiw.View继承而来的,系统提供了两种方法来设置视图:第一种也是我们最常用的的使用XML文件来配置View的相关属性,然后在程序启动时系统根 ...

  5. Android开发学习之卡片式布局的简单实现

    GoogleNow是Android4.1全新推出的一款应用,它可以全面了解你的使用习惯,并为你提供现在或者未来可能用到的各种信息,GoogleNow提供的信息关联度较高,几乎是瞬间返回答案,总而言之, ...

  6. android tabhost 生命周期,FragmentTabHost + FragmentLayout布局框架,Fragment生命周期

    使用FragmentTabHost作为底部,FrameLayout占位,搭建主页框架: android:id="@+id/home_content_fl" android:layo ...

  7. 转载 Android入门学习_代码常用布局

    1.线性布局 LinearLayout:       线性布局是所有布局中最常用的类之一,也是RadioGroup, TabWidget, TableLayout, TableRow, ZoomCon ...

  8. android开发UI界面布局教学,android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)...

    最终实现效果如下图: 具体来说就是实现了checkbox自定义选中和为选择样式,菜单项根据不同位置设置不同背景. 先上整体布局文件代码: xmlns:tools="http://schema ...

  9. 【Android开发学习24】界面布局之表格布局TableLayout+TableRow

    一.基础知识: TableLayout置底,TableRow在TableLayout的上面,而Button.TextView等控件就在TableRow之上, 另外,TableLayout之上也可以单独 ...

最新文章

  1. mysql覆盖数据_理解MySQL数据库覆盖索引
  2. Laravel添加验证场景提高针对性质的验证
  3. [LeetCode] Single Number
  4. html图片爆炸效果,利用CSS3制作3D图片爆炸效果
  5. mac mysql 设置短命令_短小强大的8个命令,分分钟帮你提高工作效率!
  6. Flutter时间工具类封装
  7. 上海交通大学2002年数学分析考研试题
  8. 小程序Canvas原有接口不再维护
  9. 关于数据库“事务”“索引”“实例”的含义
  10. Unity3D游戏开发之路:一月工作总结
  11. 替换word模板内容 Java实现
  12. ddwrt php,DDWRT脱机下载+架设网站修正加强版tar.gz模式发布
  13. 红黑联盟mysql,红黑联盟官网被人恶意留下后门
  14. Crazy Mother
  15. 基于android手机实时监控ipcam视频之三:H.264的RTP打包解析
  16. Python WindowsError
  17. java对接 布防 海康威视_java调用海康威视sdk获取车牌号demo
  18. 安全防御之入侵检测篇
  19. ICM-42670-P 六轴运动传感器 TDK ICP-10740 气压计实现运动监测
  20. 查看和学习Java官方文档

热门文章

  1. mysql导入报编码错误问题解决
  2. java多个条件排序_java定制化排序,多个条件排序
  3. python垃圾短信识别_Scikit-Learn机器学习实践:垃圾短信识别
  4. 在PowerShell中批量卸载设备
  5. .NET库和向后兼容的技巧——第2部分
  6. Ubuntu 20.10 Beta 版本发布
  7. 将JavaScript和VBScript添加到您的.NET Apps
  8. 使用gRPC的.NET Core 3.0双向消息流
  9. 到 2022 年,75% 的数据库将托管在云端
  10. W3C 宣布:WebAuthn 成为正式 Web 标准