Is there any way to add progress dialog in to the action bar sherlock from sherlock fragment (not fragment activity). I have to use sherlock fragments because in my application I use navigation drawer.
For the fragment activity, progress dialog works fine when I use following code.
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.search_all_fragment_layout);
setSupportProgressBarIndeterminateVisibility(true);
Is there any way to do this in Fragments ?
Thanks.
The ProgressBar can be shown by using this lines in your Activity:
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setSupportProgressBarIndeterminate(true);
setSupportProgressBarIndeterminateVisibility(true);
If you wanna use it in your Fragment you have to refer to the Activity:
getActivity().supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getActivity().setSupportProgressBarIndeterminate(true);
getActivity().setSupportProgressBarIndeterminateVisibility(true);
Consider making a method in your Activity which you call from the Fragment.
EDIT:
Have a method in your Activity like this:
public void activateProgressBar(boolean activite){
setSupportProgressBarIndeterminateVisibility(activate);
}
Make sure you called this in your onCreate() of the Activity:
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setSupportProgressBarIndeterminate(true);
Now just call this in your Fragment:
((YourActivity)getActivity()).activateProgressBar(true / false);
Related
I have an activity in my app, which is using swipeable tabs with action bar
For example :-
this tutorial
So my question is to add action bar to my activity and remove titlbar
similar question
I'm unsure as to exactly what you class as a title bar but you could do this in XML by putting the following in your Android Manifest for a particular activity to remove your title bar.
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen
Add this to your activity before calling setContentView();
this.requestWindowFeature(Window.FEATURE_ACTION_BAR | Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if that dosen't work try this
//use this to disable the icon from ActionBar
getActionBar().setDisplayShowHomeEnabled(false);
//use this to disable the application name from ActionBar
getActionBar().setDisplayShowTitleEnabled(false);
Use this code in oncreate() method of activity before adding content:
getWindow().requestFeature(Window.FEATURE_NO_TITLE)
When I add a fragment to my xml file, it shows all the content but not the fragment's action bar. How can I change the default behaviour to show the actionbar too?
From the Fragment, in your onCreate() method, you can try calling
getActivity().getActionBar().show();
you can set the title by using
getActivity().getActionBar().setTitle("title");
I have a Activity and it has include more than one fragment.
I know it can use requestWindowFeature(Window.FEATURE_NO_TITLE); to hide the title in Activity.
But I don't want to hide title for all fragment.
Can I hide the title for preference fragment ?
Based on what you say, you will have to use more than one activity. For the fragments that are in a same activity, the title bar is either shown or hidden.
Do not use requestWindowFeature(Window.FEATURE_NO_TITLE); We can get actionBar and hide it after setContentView
When active fragment, show action bar
When fragment detach , notify activity and activity can hide the action bar
Above is my current implement and seems work. Still testing :-D
Simple sample here - https://bitbucket.org/jimmy64/fragmentsample
I am using sherlock action bar API for action bar implementation,My problem is
I am using fragmentation in android.my main activity class is using more then 3
fragments to display things now I need to access that action bar in every fragment
but whenever I moved from main activity to any other fragments action bar is not
accessible there. when ever I call any action it gives my null pointer exception kindly need your help.
Be sure that other fragments are extending SherlockFragment
And then call this method:
this.getSherlockActivity().getSupportActionBar().setTitle(TheString);
if I understand the question, you need to reach the actionbar from the fragment inside an activity. So once you reach the activity from the fragment, from there you can get the actionbar. say that you need to set the title:
from the fragment (it should be a SherlockFragment) do the following
getSherlockActivity().getSupportActionBar().setTitle(theTitle);
I have an action bar set up in the main activity, and this creates a bunch of fragments. However, there are several fragments that require the action bar to be hidden, but I can't refer to the ActionBarSherlock class inside a fragment.
How can I hide the action bar?
Thanks for any suggestions.
Actually you can refer to ActionBar via activity which you can get from a SherlockFragment by calling SherlockFragment.getSherlockActivity(), then just call SherlockFragmentActivity.getSupportActionBar() and then hide()