在所有应用程序中全屏切换

时间:2015-12-13 17:17:31

标签: android togglebutton android-fullscreen android-togglebutton

在我之前的帖子Fullscreen switching中,我尝试了下一个代码:

var models = require('../models');

var users = models.users;

users.hasMany(models.images, {as: 'Images'});
console.log(users.getImages());

它的工作,但只有一项活动。我怎么能为所有申请做到这一点?

2 个答案:

答案 0 :(得分:0)

创建一个Activity类,其他所有类extends。例如

public abstract class BaseActivity extends AppCompatActivity {
    protected abstract boolean toggleFullScreen();

    @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (toggleFullScreen()) {
            //fullScreen
        }
    }
}

现在而不是在其他AppCompatActivity中展开Activity,而不是BaseActivity

答案 1 :(得分:0)

始终在Application class下进行通用初始化。

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();       
        onActivityLifecycleCallback();

    }

    private void onActivityLifecycleCallback() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

           @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

 if (isChecked)
            {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            }
        else
            {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            }


        });
    }

}

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">