Wednesday, August 8, 2012

Hide/remove navigation bar on nexus 7 for developer

On Android 4.1, the navigation bar contains the "back", "home" and "recent apps" buttons. If you play a movie or display a big picture, hide or remove the navigation bar is the best way to leave for more space, like watching YouTube video fullscreen in landscape. To develop Android app for nexus 7 tablet with the features, you can try the following codes:

package com.exercise.AndroidthePicture;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class AndroidBigPictureActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ImageView myImageView = (ImageView)findViewById(R.id.myimageview);
        myImageView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <HorizontalScrollView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
        <ScrollView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
            <ImageView 
                android:id="@+id/myimageview"
                android:src="@drawable/bigpicture"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content"
                android:scaleType="center"/>
        </ScrollView>
 </HorizontalScrollView>
</LinearLayout>


When app starts, the navigation bar hide. If you touch on the screen, the navigation bar comes back.

No comments:

Post a Comment