问题
i need help for this . I realize sth very strange about this. In order to disable the Action bar (Title) , i need to add in this code
requestWindowFeature(Window.FEATURE_NO_TITLE);
So this only works I change from
extends AppCompatActivity
To this
extends Activity
So after changing that, I got error for the getFragmentManager.
Please have a look at the screenshot. And let me know if u guys have any idea wads going on? THx
回答1:
Use getSupportFragmentManager()
instead of getFragmentManager()
.
AppCompatActivity
is v4 library therefore required to use v4 functions
And to use it in Activity
instead of Activity
change it to FragmentActivity
. Then you can use getSupportFragmentManager()
回答2:
requestWindowFeature() is not supported in AppCompatActivity thats why you could not use that method with AppCompatActivity.
Also if you are using AppCompatActivity you need to use SupportFragment and if you use Activity then use Fragment.
回答3:
If you are using this import import android.support.v4.app.Fragment;
,
then you must use getSupportFragmentManager.
Hope this helps.
回答4:
You have to use the Compat method getSupportFragmentManager()
instead of the regular one.
That's because it returns an object of type android.app.FragmentManager which is the type of the object where you're trying to store it.
If you use the regular method getFragmentManager()
it'll return an object of type android.app.FragmentManager, which is an incompatible type.
来源:https://stackoverflow.com/questions/38453111/getfragmentmanager-vs-getsupportfragmentmanager-error