default:
break;
}
}
public static interface OnTabChangeListener {
public void onTabChange(String tag);
}
}
二、对应底部Tab的XML布局文件
<FrameLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1.0” >
<Button
android:id=“@+id/button_state1”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@null”
android:button=“@null”
android:drawableTop=“@drawable/ic_message_selector”
android:gravity=“center”
android:singleLine=“true”
android:tag=“message”
android:text=“@string/text_tab_message”
android:textColor=“@color/text_service_color”
android:textSize=“14dp” />
<FrameLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1.0” >
<Button
android:id=“@+id/button_state2”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@null”
android:button=“@null”
android:drawableTop=“@drawable/ic_service_selector”
android:gravity=“center”
android:singleLine=“true”
android:tag=“service”
android:text=“@string/text_tab_service”
android:textColor=“@color/text_service_color”
android:textSize=“14dp” />
<FrameLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1.0” >
<Button
android:id=“@+id/button_state3”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@null”
android:button=“@null”
android:drawableTop=“@drawable/ic_profile_selector”
android:gravity=“center”
android:singleLine=“true”
android:tag=“personal”
android:text=“@string/text_tab_profile”
android:textColor=“@color/text_service_color”
android:textSize=“14dp” />
<FrameLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1.0” >
<Button
android:id=“@+id/button_state4”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@null”
android:button=“@null”
android:drawableTop=“@drawable/ic_setting_selector”
android:gravity=“center”
android:singleLine=“true”
android:tag=“settings”
android:text=“@string/text_tab_setting”
android:textColor=“@color/text_service_color”
android:textSize=“14dp” />
三、在启动的Acitvity界面中使用自定义的Tab类
<?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” >
<FrameLayout
android:id=“@+id/layout_content”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1.0” />
<app.ui.widget.TabView
android:id=“@+id/view_tab”
android:layout_width=“match_parent”
android:layout_height=“@dimen/header_height”
android:background=“@color/tab_main_color” />
四、自定义类处理Fragment返回重叠的问题
/*******************************************************************************
-
Copyright © Baina Info Tech Co. Ltd
-
FragmentUtils
-
app.util.FragmentUtils.java
-
TODO: File description or class description.
-
@changeLogs:
-
1.0.0: First created this class.
******************************************************************************/
package app.util;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
/**
-
FragmentUtils of MyHealth
-
@author qixiao
*/
public class FragmentUtils {
private FragmentUtils() {
}
public static Fragment replaceFragment(FragmentManager fragmentManager, int container,
Class<? extends Fragment> newFragment, Bundle args) {
return replaceFragment(fragmentManager, container, newFragment, args, false);
}
public static Fragment replaceFragment(FragmentManager fragmentManager, int container,
Fragment newFragment) {
return replaceFragment(fragmentManager, container, newFragment, false);
}
public static Fragment replaceFragment(FragmentManager fragmentManager, int container,
Class<? extends Fragment> newFragment, Bundle args, boolean addToBackStack) {
Fragment fragment = null;
// 构造新的Fragment
try {
fragment = newFragment.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (fragment != null) {
// 设置参数
if (args != null && !args.isEmpty()) {
final Bundle bundle = fragment.getArguments();
if (bundle != null) {
bundle.putAll(args);
} else {
fragment.setArguments(args);
}
}
// 替换
return replaceFragment(fragmentManager, container, fragment, addToBackStack);
} else {
return null;
}
}
public static Fragment replaceFragment(FragmentManager fragmentManager, int container,
Fragment newFragment, boolean addToBackStack) {
final FragmentTransaction transaction = fragmentManager.beginTransaction();
final String tag = newFragment.getClass().getSimpleName();
if (newFragment != null) {
transaction.replace(container, newFragment, tag);
}
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.commitAllowingStateLoss();
return newFragment;
}
public static Fragment switchFragment(FragmentManager fragmentManager, int container,
Fragment currentFragment, Class<? extends Fragment> newFragment, Bundle args) {
return switchFragment(fragmentManager, container, currentFragment, newFragment, args, false);
}
/**
-
@param fragmentManager
-
@param container
-
@param currentFragment
-
@param newFragment
-
@param args 新Fragment的参数
-
@param addToBackStack 这个操作是否加入栈中,如果要实现类似返回效果,则需要。
-
@return 新显示的Fragment
*/
public static Fragment switchFragment(FragmentManager fragmentManager, int container,
Fragment currentFragment, Class<? extends Fragment> newFragment, Bundle args,
boolean addToBackStack) {
final FragmentTransaction transaction = fragmentManager.beginTransaction();
final String tag = newFragment.getSimpleName();
Fragment fragment = fragmentManager.findFragmentByTag(tag);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
资源分享
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。
2020年虽然路途坎坷,都在说Android要没落,但是,不要慌,做自己的计划,学自己的习,竞争无处不在,每个行业都是如此。相信自己,没有做不到的,只有想不到的。祝大家2021年万事大吉。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
droid)**
[外链图片转存中…(img-Jyjsf2Np-1712621699387)]
资源分享
[外链图片转存中…(img-etMtPKz0-1712621699388)]
[外链图片转存中…(img-ZUULJviF-1712621699388)]
[外链图片转存中…(img-KzAtLJEy-1712621699388)]
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。
2020年虽然路途坎坷,都在说Android要没落,但是,不要慌,做自己的计划,学自己的习,竞争无处不在,每个行业都是如此。相信自己,没有做不到的,只有想不到的。祝大家2021年万事大吉。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-Q4J7OhzE-1712621699389)]