【问题标题】:Action Bar Tab change with tablet orientation操作栏选项卡随平板电脑方向变化
【发布时间】:2023-03-13 08:40:01
【问题描述】:

我有一个活动,其中包含一些片段。

我的问题发生在将平板电脑的方向更改为垂直时。 操作栏选项卡发生变化,而不是在改变方向时保持不变。

当改变方向时,其他片段选项卡消失,我不知道为什么。我发两张图。更改前的第一个和更改后的第二个。

这是一些代码......

  @Override
public void onTabSelected(CompatTab tab, FragmentTransaction ft) {
    Fragment fragment = tab.getFragment();
    //Fragment fragment = mActivity.getSupportFragmentManager().findFragmentByTag(TAB_MAIN);
    if(fragment==null){
        fragment = Fragment.instantiate(mActivity, mClass.getName());
        tab.setFragment(fragment);
        ft.add(android.R.id.tabcontent, fragment, tab.getTag());
    }else{
        ft.attach(fragment);
    }       
}

  Inside the manifest....
     <activity android:name="ClientEditActivity"
              android:configChanges="orientation|screenSize"
              android:screenOrientation="unspecified"/>

【问题讨论】:

    标签: android tabs android-fragments screen-orientation


    【解决方案1】:

    因此,当您旋转屏幕时,Android 会销毁所有活动并重建它们。也许你需要检查你的代码,看看是否有一些 Activity 创建/销毁 ActionBar 上的按钮。

    你能把创建ActionBar的代码放上来吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      相关资源
      最近更新 更多