I am creating a framework for an application and want to hide the action bar for login activity. The application will consist entirely of fragments because they are awesome.
I can hide the action bar perfectly for my activity, but every time I launch the application, I see my bloated empty fragment and the default action bar for about 2 seconds before it can inflate the input fragment.
Any idea on how / where should I hide the action bar (keeping my structure) in order to stop this?
LoginActivity.java
public class LoginActivity extends SingleFragmentActivity { @Override protected Fragment createFragment() { return new LoginFragment(); }
}
SingleFragmentActivity.java
public abstract class SingleFragmentActivity extends ActionBarActivity { protected abstract Fragment createFragment(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(this instanceof LoginActivity){ ActionBar actionBar = getSupportActionBar(); actionBar.hide(); } setContentView(R.layout.activity_fragment); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); if (fragment == null) { fragment = createFragment(); fm.beginTransaction() .add(R.id.fragmentContainer, fragment) .commit(); } }
}
LoginFragment.java
public class LoginFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_login, parent, false); return v; }
}
I originally had a SingleFragmentActivity, extending FragmentActivity and did this in the if statement:
requestWindowFeature(Window.FEATURE_NO_TITLE);
But I have the feeling that just another way to do the same
Edit:
I also tried setting a different style for the fragment_activity parameter, but it doesn't work either:
<style name="NoActionBar" parent="Widget.AppCompat.ActionBar"> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> </style>