我设计了我的应用程序以全屏模式工作。没有状态栏和操作栏都可见。这是一个问题,因为每次使用YoutubeAndroidPlayerAPI从youtube加载视频时,都会出现状态栏。

我的活动:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.activity_open_translate,R.anim.activity_close_scale);

    this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    if(getActionBar()!=null) {

        ActionBar actionBar = getActionBar();
        actionBar.hide();
    }
    setContentView(R.layout.activity_fad_socios);
    ...
}
...
private void changeFragment(int index) {

    switch(index) {

        case 0:{
            getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new FADFragment(),"informacion").commit();
            break;
        }
    ...
}


我引用YoutubeAPI的方式包括我的片段:

            fragmentManager = getActivity().getSupportFragmentManager();
            fragmentTransaction = fragmentManager.beginTransaction();

            fragment = new YouTubePlayerSupportFragment();
            fragmentTransaction.add(R.id.fragmentz, fragment);
            fragmentTransaction.commit();

                    portadaFrag.setVisibility(View.GONE);

                    if(buttonSelected == 0) {

                        ((FADSociosActivity) getActivity()).playingYoutube=true;

                        fragment.initialize(getActivity().getResources().getString(R.string.youKEY), new OnInitializedListener(){

                            @Override
                            public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {

                                Log.e("fail","fail");
                            }

                            @Override
                            public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1, boolean arg2) {

                                youtubePlayer = arg1;

                                youtubePlayer.loadVideo("-D-MVgOvvOo");

                                youtubePlayer.setPlaybackEventListener(new PlaybackEventListener() {

                                    @Override
                                    public void onBuffering(boolean arg0) {

                                        try {
                                            ((FADSociosActivity) getActivity()).refreshWindow();
                                        }
                                        catch(Exception e) {}
                                    }

                                    @Override
                                    public void onPaused() {

                                        try {
                                            ((FADSociosActivity) getActivity()).playingYoutube=false;
                                            ((FADSociosActivity) getActivity()).refreshWindow();
                                        }
                                        catch(Exception e) {}
                                    }

                                    @Override
                                    public void onPlaying() {

                                        try {

                                            youtubePlayButton.setVisibility(View.GONE);
                                            ((FADSociosActivity) getActivity()).playingYoutube=true;
                                            ((FADSociosActivity) getActivity()).refreshWindow();
                                        }
                                        catch(Exception e) {}
                                    }

                                    @Override
                                    public void onSeekTo(int arg0) {

                                        try {
                                            ((FADSociosActivity) getActivity()).refreshWindow();
                                        }
                                        catch(Exception e) {}
                                    }

                                    @Override
                                    public void onStopped() {

                                        try {

                                            youtubePlayButton.setVisibility(View.VISIBLE);
                                            ((FADSociosActivity) getActivity()).playingYoutube=false;
                                            ((FADSociosActivity) getActivity()).refreshWindow();
                                        }
                                        catch(Exception e) {}
                                    }

                                });


我在第一个活动中的refreshWindow方法:

public void refreshWindow() {

    try {

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().getDecorView().findViewById(android.R.id.content).invalidate();
    }
    catch(Exception e) {

        e.printStackTrace();
    }
}


使用此方法后,状态栏会出现一些不希望有的倾斜,从而无法迫使活动再次进入全屏模式。无论如何,每次用户点击视频时,活动都会退出全屏模式。似乎YoutubePlayer-API覆盖了我的FLAG_FULLSCREEN,我无法避免这一点。有谁知道该如何克服?提前致谢。

最佳答案

好吧,在初始化后设置标志YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION似乎可以解决问题=)

关于android - Android youtube-api取消 Activity 中的FLAG_FULLSCREEN,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21682255/

10-09 12:46