1

在我之前的帖子全屏切换中,我尝试了下一个代码:

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

这是工作,但只针对一项活动。我怎样才能为所有应用程序做到这一点?

4

2 回答 2

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

于 2015-12-13T17:21:13.983 回答
0

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

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">
于 2015-12-13T17:31:32.277 回答