I have a Activity as below:
// My Activity Holding Fragment
public class MyActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_activity_main);
}
}
// My Fragment
public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.my_fragment, container, false);
return view;
}
}
I wan to have the Title Bar for my Activity.
I want to Hide or Show Title Bar from Activity and Frgment on some conditions.
I tried below solutions, but as my activity does not derive from ActionBarActivity it does not work.
// getSupportActionBar returns null
getSupportActionBar().hide();
getSupportActionBar().show();
// getActionBar returns null
getActionBar().hide();
getActionBar().show();
// findViewById returns null
findViewById(android.R.id.title).setVisibility(View.GONE);
findViewById(android.R.id.title).setVisibility(View.VISIBLE);
// Are deprecated
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
None of the solutions did work for hiding Title Bar from Activity or Fragment.
Basically I want to hide the Activity title bar for the Activity.
First Change your App theme from res/value/styles.xml to this
After that Add toolbar in your Activity's XML Layout
Now finally set up your toolbar in Activity Class
Same would be applicable for fragment but for fragment you need to call view first