XML : Title bar keeps hiding on tabbed activity, How can I stop this?

I'm writing an android application which uses two tabs for its main UI. Each tab has its own fragment and is managed by one activity called LoggedInTabs.

Here is my code for it as below...

  public class LoggedInTabs extends AppCompatActivity {          private void setupTabs() {          Toolbar toolbar;          TabLayout tabLayout;          ViewPager viewPager;          toolbar = (Toolbar) findViewById(R.id.toolbar);          setSupportActionBar(toolbar);          viewPager = (ViewPager) findViewById(R.id.viewpager);          setupViewPager(viewPager);          tabLayout = (TabLayout) findViewById(R.id.tabs);          tabLayout.setupWithViewPager(viewPager);      }        // Helper      public void hidekb() {          // Check if no view has focus:          View view = this.getCurrentFocus();          if (view != null) {              InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);              imm.hideSoftInputFromWindow(view.getWindowToken(), 0);          }      }        @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_logged_in_tabs);          hidekb();          // Set up the tab toolbar..          setupTabs();      }        private void setupViewPager(ViewPager viewPager) {          ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());          adapter.addFragment(new fragment_confirm(), "Confirm");          adapter.addFragment(new fragment_user(), "User");          viewPager.setAdapter(adapter);      }        class ViewPagerAdapter extends FragmentPagerAdapter {          private final List<Fragment> mFragmentList = new ArrayList<>();          private final List<String> mFragmentTitleList = new ArrayList<>();            public ViewPagerAdapter(FragmentManager manager) {              super(manager);          }            @Override          public Fragment getItem(int position) {              return mFragmentList.get(position);          }            @Override          public int getCount() {              return mFragmentList.size();          }            public void addFragment(Fragment fragment, String title) {              mFragmentList.add(fragment);              mFragmentTitleList.add(title);          }            @Override          public CharSequence getPageTitle(int position) {              return mFragmentTitleList.get(position);          }      }  }    

This works fine and I can switch between confirm and user pages happily.

The problem I have is that in my confirm fragment I have an edit text field. If I am 'editing' this field, then switch tabs the keyboard does not close and worse still closing the keyboard on the different fragment hides the title bar! (I can still see the tabs!) Obviously I will need the title bar to definitely stay and never hide. Any ideas how to stop this behavior?

If it helps also i will include my theme used in the activity:

  <!-- Base application theme. -->      <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">          <!-- Customize your theme here. -->          <item name="colorPrimary">@color/colorPrimary</item>          <item name="colorPrimaryDark">@color/colorPrimaryDark</item>          <item name="colorAccent">@color/colorAccent</item>          <item name="windowActionBar">false</item>          <item name="windowNoTitle">true</item>      </style>  <style name="AppTheme.NoActionBar">          <item name="android:windowActionBar">false</item>          <item name="windowActionBar">false</item>          <item name="windowNoTitle">true</item>      </style>    

And here is the activity in the manifest:

  <activity android:name=".LoggedInTabs"              android:screenOrientation="portrait"              android:windowSoftInputMode="adjustResize|stateHidden"              android:theme="@style/AppTheme.NoActionBar"/>    

No comments:

Post a Comment