case 0:
mStateButton1.setSelected(true);
case 1:
mStateButton2.setSelected(true);
tag = mStateButton2.getTag();
case 2:
mStateButton3.setSelected(true);
tag = mStateButton3.getTag();
case 3:
mStateButton4.setSelected(true);
tag = mStateButton4.getTag();
break;
break;
}
if (mOnTabChangedListener != null) {
if (tag != null && mOnTabChangedListener != null) {
mOnTabChangedListener.onTabChange(tag.toString());
} else {
mOnTabChangedListener.onTabChange(null);
}
}
*/
// TODO Auto-generated method stub
break;
break;
break;
switchState(3);
break;
break;
}
}
public static interface OnTabChangeListener {
public void onTabChange(String tag);
}
}
android:layout_width=“match_parent”
android:layout_height=“match_parent”
<Button
android:id=”@+id/button_state1″
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=”@null”
android:drawableTop=”@drawable/ic_message_selector“
android:text=”@string/text_tab_message”
android:textColor=”@color/text_service_color“
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:drawableTop=”@drawable/ic_service_selector“
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: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:singleLine=“true”
android:tag=“settings”
android:text=”@string/text_tab_sett
ing”
android:textColor=”@color/text_service_color”
android:textSize=“14dp” />
<?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” />
android:layout_width=“match_parent”
android:layout_height=”@dimen/header_height”
android:background=”@color/tab_main_color” />
/*******************************************************************************
******************************************************************************/
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
/**
*/
}
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) {
} catch (IllegalAccessException e) {
}
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);
}
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);
}
/**
}
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的参数
-
@return 新显示的Fragment
原文地址:https://blog.csdn.net/m0_66264324/article/details/122759628
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_12799.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!