0

I am developing an app that will display a video as a "backdrop" and have text and other views on top of it (using a FrameLayout).

For some reason, when immersive mode enabled, the textview I am using to test disappears, though it does reappear when swiping to show the system nav/status bars.

Here is my code:

public class MainActivity extends Activity{

    private Uri video;
    private PowerManager.WakeLock wl;
    private FrameLayout frame;
    private TextView text;
    private VideoView videoview;
    private FrameLayout.LayoutParams layoutParams;

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

        frame = (FrameLayout) findViewById(R.id.frame);
        text = (TextView) findViewById(R.id.text_field_1);
        videoview = (VideoView) findViewById(R.id.video_view);

        resetDisplay();
        getWindow().setFormat(PixelFormat.UNKNOWN);

        videoview.setOnPreparedListener(new OnPreparedListener(){
            @Override
            public void onPrepared(MediaPlayer mp){
                mp.setLooping(true);
            }
        });

        video = Uri.parse(Environment.getExternalStorageDirectory()+"/video.avi");
        videoview.setZOrderOnTop(false);
        videoview.setVideoURI(video);
        videoview.start();
        text.bringToFront();

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {}

    }

    protected void onPause(){
        super.onPause();
        videoview.suspend();
        wl.release();
    }

    protected void onResume(){
        super.onResume();
        resetDisplay();
        videoview.start();
        wl.acquire();
    }

    private void resetDisplay()
    {
        frame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
                View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                View.SYSTEM_UI_FLAG_LOW_PROFILE);

    }

}

And my layout XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clipChildren="false"
    android:id="@+id/frame"
    tools:context="com.example.exampleapp.MainActivity" >

    <VideoView
        android:id="@+id/video_view"
        android:clickable="false"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="true"        
        />

    <TextView
        android:id="@+id/text_field_1"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />


</FrameLayout>

Does anyone know how to force the text to appear in immersive mode on top of the video?

Thanks!

Scott
  • 1
  • 2

1 Answers1

0

Try setting the

android:layout_gravity

property of your TextView.

For example

android:layout_gravity="center" 

or

android:layout_gravity="bottom|center_horizontal"

How to get a textview centred on top of an ImageView

How to show one layout on top of the other programmatically in my case?

Put any View over a VideoView in Android

Community
  • 1
  • 1
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53
  • That works to move the text to the center of the screen, but it still disappears when the system UI is hidden. – Scott Jul 16 '14 at 13:21