我试图找到是否可以在非Web应用程序中使用togglz - 就像我们有普通的java项目或java批处理程序一样。
我尝试在独立应用程序中添加togglz库并尝试运行它。
这是我的代码段 -
Its Work in My RecyclerView try this:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>
You need to disable nested scrolling programatically. It doesn't seem to work correctly if done in xml.
recyclerView.setNestedScrollingEnabled(false);
它说 -
import com.feature.MyFeature;
public class Test {
public static void main(String[] args) {
Test t = new Test();
boolean valid=t.validate("CREATE_TEAM");
System.out.println(valid);
}
public boolean validate(String feature){
if (MyFeature.valueOf(feature).isActive()) {
return true;
}
return false;
}
}
答案 0 :(得分:3)
您必须正确配置Togglz才能使其正常工作。在独立应用程序中,我建议进行以下设置。
首先使用FeatureManager
创建FeatureManagerBuilder
。像这样:
FeatureManager featureManager = FeatureManagerBuilder.begin()
.featureEnum(Features.class)
.stateRepository(new InMemoryStateRepository())
.userProvider(new NoOpUserProvider())
.build();
告诉您StaticFeatureManagerProvider
关于您的经理:
StaticFeatureManagerProvider.setFeatureManager(featureManager);
现在StaticFeatureManagerProvider
可以告诉Togglz你的FeatureManager
,一切都应该正常工作!
Features.FOOBAR.isActive();
// > false