是否可以在非Web应用程序中使用togglz

时间:2017-02-17 11:26:52

标签: java togglz

我试图找到是否可以在非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;
    }

}

1 个答案:

答案 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
相关问题