本文整理汇总了Java中android.support.v4.app.FragmentTransaction.show方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.show方法的具体用法?Java FragmentTransaction.show怎么用?Java FragmentTransaction.show使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.show方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showHideFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public static void showHideFragment(FragmentManager manager, Fragment show, Fragment hide, boolean animation, boolean backStack) {
FragmentTransaction transaction = manager.beginTransaction();
if (animation) {
transaction.setCustomAnimations(
R.anim .fragment_translate_in, R.anim.fragment_translate_out
,R.anim.fragment_pop_in,R.anim.fragment_pop_out);
}
transaction.show(show);
if (hide == null) {
List<Fragment> fragments = manager.getFragments();
if (fragments != null) {
for (Fragment fragment : fragments) {
if (fragment != show) {
transaction.hide(fragment);
}
}
}
} else {
transaction.hide(hide);
}
if (backStack) {
transaction.addToBackStack("showHideFragment");
}
transaction.commit();
}
示例2: showOneFragmentOnBackPressed
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 返回键显示特定Tag的Fragment
*/
private void showOneFragmentOnBackPressed() {
mFragmentBackDeque.pop();
String fragmentTab = mFragmentBackDeque.peek();
FragmentManager manager = getSupportFragmentManager();
if (manager != null) {
FragmentTransaction transaction = manager.beginTransaction();
transaction.setCustomAnimations(R.anim.left_enter, R.anim.right_exit, 0, 0);
List<Fragment> fragments = manager.getFragments();
for (Fragment f : fragments) {
if (f != null) {
transaction.hide(f);
}
}
Fragment fragmentByTag = manager.findFragmentByTag(fragmentTab);
if (fragmentByTag != null) {
mCurrentFragment = fragmentByTag;
transaction.show(fragmentByTag);
}
transaction.commitAllowingStateLoss();
}
}
示例3: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void switchFragment(BaseFragment fragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
for (int i = 0; i < this.mFragments.size(); i++) {
BaseFragment item = (BaseFragment) this.mFragments.get(i);
this.currentIndex = i;
if (item == fragment) {
if (!fragment.isAdded()) {
transaction.add((int) R.id.frame_content, (Fragment) fragment);
fragment.loadFirst();
}
transaction.show(fragment);
} else if (item.isAdded()) {
transaction.hide(item);
}
}
transaction.commitAllowingStateLoss();
}
示例4: handleFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void handleFragment(BaseFragment baseFragment, boolean isChecked) {
FragmentTransaction fragmentTransaction = context.getSupportFragmentManager().beginTransaction();
if (isChecked) {
fragmentTransaction.show(baseFragment);
} else {
fragmentTransaction.hide(baseFragment);
}
fragmentTransaction.commit();
}
示例5: showFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showFragment(int index) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
hideFragment(ft);
switch (index) {
case 0:
if (mHomeFragment == null) {
mHomeFragment = new HomeFragment();
ft.add(R.id.main_content, mHomeFragment);
} else {
ft.show(mHomeFragment);
}
break;
case 1:
if (mGameTypeFragment == null) {
mGameTypeFragment = new GameTypeFragment();
ft.add(R.id.main_content, mGameTypeFragment);
} else {
ft.show(mGameTypeFragment);
}
break;
case 2:
if (mSearchFragment == null) {
mSearchFragment = new DiscoveryFragment();
ft.add(R.id.main_content, mSearchFragment);
} else {
ft.show(mSearchFragment);
}
break;
case 3:
if (mMeFragment == null) {
mMeFragment = new MeFragment();
ft.add(R.id.main_content, mMeFragment);
} else {
ft.show(mMeFragment);
}
break;
}
ft.commit();
}
示例6: onBackPressed
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onBackPressed() {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else if (mFragmentStack.size() > 1) {
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
if (mCurrentFragmentId != NAVIGATE_ID && mCurrentFragmentId != DETAILS_ISSUE_ID
&& mCurrentFragmentId != DETAILS_QR_ID && mCurrentFragmentId != DETAILS_AWARD_ID
&& mCurrentFragmentId != DETAILS_ACHIEVEMENTS_ID
&& mCurrentFragmentId != DETAILS_EVENTS_ID) {
BasicFragment fragment = (BasicFragment) mFragmentStack.pop();
fragmentTransaction.remove(fragment);
while (fragment.getFragmentId() != NAVIGATE_ID) {
fragment = (BasicFragment) mFragmentStack.pop();
}
mFragmentStack.clear();
mFragmentStack.add(fragment);
fragment.onResume();
fragmentTransaction.show(fragment).commit();
mCurrentFragmentId = NAVIGATE_ID;
mCurrentFragment = fragment;
} else {
mFragmentStack.lastElement().onPause();
fragmentTransaction.remove(mFragmentStack.pop());
mFragmentStack.lastElement().onResume();
BasicFragment restoredFragment = (BasicFragment) mFragmentStack.lastElement();
fragmentTransaction.show(restoredFragment);
fragmentTransaction.commit();
mCurrentFragment = restoredFragment;
mCurrentFragmentId = restoredFragment.getFragmentId();
}
setToolbarTitle();
updateMenu();
updateDrawerMenu();
} else {
super.onBackPressed();
}
}
示例7: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void switchFragment(BaseFragment fragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
for (BaseFragment item : this.mFragments) {
if (item == fragment) {
if (!fragment.isAdded()) {
transaction.add((int) R.id.frame_content, (Fragment) fragment);
fragment.loadFirst();
}
transaction.show(fragment);
} else if (item.isAdded()) {
transaction.hide(item);
}
}
transaction.commitAllowingStateLoss();
}
示例8: setFragments
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/** 界面切换控制 */
public void setFragments(int index) {
for (int i = 0; i < mFragments.size(); i++) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
Fragment fragment = mFragments.get(i);
if (i == index) {
ft.show(fragment);
} else {
ft.hide(fragment);
}
ft.commit();
}
mCurrentTab = index;
}
示例9: showTab
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showTab(int idx) {
for (int i = 0; i < fragments.size(); i++) {
Fragment fragment = fragments.get(i);
FragmentTransaction ft = obtainFragmentTransaction(idx);
if (idx == i) {
ft.show(fragment);
} else {
ft.hide(fragment);
}
ft.commit();
}
currentTab = idx;
}
示例10: onCreate
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
FragmentTransaction ft = getFragmentManager().beginTransaction();
if (isSupportHidden) {
ft.hide(this);
} else {
ft.show(this);
}
ft.commit();
}
}
示例11: showBookmarksFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showBookmarksFragment() {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.show(bookmarksFragment);
fragmentTransaction.hide(mainFragment);
fragmentTransaction.commit();
toolbar.setTitle(getResources().getString(R.string.nav_bookmarks));
if (bookmarksFragment.isAdded()) {
bookmarksFragment.notifyDataChanged();
}
}
示例12: showPackagesFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* Show the packages list fragment.
*/
private void showPackagesFragment() {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.show(packagesFragment);
fragmentTransaction.hide(companiesFragment);
fragmentTransaction.commit();
toolbar.setTitle(getResources().getString(R.string.app_name));
navigationView.setCheckedItem(R.id.nav_home);
}
示例13: showCompaniesFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* Show the companies list fragment.
*/
private void showCompaniesFragment() {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.show(companiesFragment);
fragmentTransaction.hide(packagesFragment);
fragmentTransaction.commit();
toolbar.setTitle(getResources().getString(R.string.nav_companies));
navigationView.setCheckedItem(R.id.nav_companies);
}
示例14: showMediaPreviewFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void showMediaPreviewFragment() {
mSelectedIndex = 2;
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
mMediaPreviewFragment = MediaPreviewFragment.newInstance(mConfiguration, mPreviewPosition);
ft.add(R.id.fragment_container, mMediaPreviewFragment);
mMediaPageFragment = null;
ft.hide(mMediaGridFragment);
ft.show(mMediaPreviewFragment);
ft.commit();
String title = getString(R.string.gallery_page_title, mPreviewPosition, mCheckedList.size());
mTvToolbarTitle.setText(title);
}
示例15: onCreate
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
FragmentTransaction ft = getFragmentManager().beginTransaction();
if (isSupportHidden) {
ft.hide(this);
} else {
ft.show(this);
}
ft.commit();
}
Log.d(TAG, "onCreate: ");
}