AppcompatDelegate getSupportFragmentManager()
AppcompatDelegate getSupportFragmentManager()
我的 activity 应该继承自另一个 activity(另一个我无权访问的库),我需要在我的新 Activity 中集成 ActionBar + Fragments。我使用 AppCompatDelegate
.
成功集成了操作栏
@Override
protected void onCreate(Bundle savedInstanceState) {
//the installViewFactory method replaces the default widgets
//with the AppCompat-tinted versions
getDelegate().installViewFactory();
super.onCreate(savedInstanceState);
getDelegate().onCreate(savedInstanceState);
getDelegate().setContentView(R.layout.activity_profile);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
getDelegate().setSupportActionBar(toolbar);
getDelegate().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
...
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
问题是如何在从 android.app.Activity
延伸的 activity 中使用片段?
注意:这不是 FragmentActivity
!
如果 android.app.Activity 是您唯一可以使用的真正超类,我想您将不得不使用平台片段(android.app.Fragment 的子类)而不是兼容库片段,它将仅适用于 API 11 及更高版本,当它们被引入时。 getFragmentManager() 是您的切入点。
我的 activity 应该继承自另一个 activity(另一个我无权访问的库),我需要在我的新 Activity 中集成 ActionBar + Fragments。我使用 AppCompatDelegate
.
@Override
protected void onCreate(Bundle savedInstanceState) {
//the installViewFactory method replaces the default widgets
//with the AppCompat-tinted versions
getDelegate().installViewFactory();
super.onCreate(savedInstanceState);
getDelegate().onCreate(savedInstanceState);
getDelegate().setContentView(R.layout.activity_profile);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
getDelegate().setSupportActionBar(toolbar);
getDelegate().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
...
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
问题是如何在从 android.app.Activity
延伸的 activity 中使用片段?
注意:这不是 FragmentActivity
!
如果 android.app.Activity 是您唯一可以使用的真正超类,我想您将不得不使用平台片段(android.app.Fragment 的子类)而不是兼容库片段,它将仅适用于 API 11 及更高版本,当它们被引入时。 getFragmentManager() 是您的切入点。