对于 android 的新架构组件,您不能使用 android 提供的默认自动生成类抽屉导航类...为什么?因为它从 AppCompatActivity 扩展为工具栏等小部件提供 support.v7 lib 的使用。现在使用新架构组件 Lifecycleactivity 而不是扩展 AppCompatActivity 时,您无法实现默认的抽屉导航类 - 谁能给我一个解决方法或一个如何做到这一点的例子?
最佳答案
Note: Since the Architecture Components are in alpha stage, Fragment and AppCompatActivity classes cannot implement it (because we cannot add a dependency from a stable component to an unstable API). Until Lifecycle is stable, LifecycleActivity and LifecycleFragment classes are provided for convenience. After the Lifecycles project is released, support library fragments and activities will implement the LifecycleOwner interface; LifecycleActivity and LifecycleFragment will be deprecated at that time.
他们继续提供 instructions for implementing a LifecycleOwner ,它允许您避免使用 LifecycleActivity
:
public class MyActivity extends AppCompatActivity
implements LifecycleRegistryOwner {
LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
@Override
public LifecycleRegistry getLifecycle() {
return lifecycleRegistry;
}
}
关于android - 使用 android 架构组件实现侧边栏导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45220402/