I have 3 activities in my app, main one and 2 others. Inside the main one, I used this code inside the onCreate method to make the app run fullscreen:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.findViewById(R.id.main_screen).setOnTouchListener(this);
width = Util.getInstance().getScreenWidth(this);
height = Util.getInstance().getScreenHeight(this);
String imagePath = PreferenceManager.getDefaultSharedPreferences(this).getString("IMAGE_PATH", "NULL");
if (!"NULL".equals(imagePath) && new File(imagePath).exists()){
Util.IMAGE_PATH = imagePath;
setImage();
}
}
I used the same code inside the other 2 activities, shown below, but they don't seem to have any effect. It still doesn't display it in fullscreen like the Main one does. Here are the other two activities:
public class Pass extends Activity implements OnClickListener, OnKeyListener, OnTouchListener{
EditText etPassword;
public static StringBuilder pass;
public static String replace;
static boolean keyDel = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pass);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
etPassword = (EditText) findViewById(R.id.password);
final StringBuilder stringBuilderHiddenPassword = new StringBuilder();
final StringBuilder mPass = new StringBuilder();
pass = new StringBuilder();
etPassword.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DEL){
keyDel = true;
}else{
keyDel = false;
}
return false;
}
});
etPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!keyDel){
stringBuilderHiddenPassword.append("*");
etPassword.removeTextChangedListener(this);
etPassword.setText(stringBuilderHiddenPassword);
etPassword.addTextChangedListener(this);
}
}
@Override
public void afterTextChanged(Editable s) {
pass.append(s);
replace = pass.toString().replace("*", "");
}
});
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.findViewById(R.id.pass_screen).setBackgroundColor(Color.argb(100, 0, 0, 0));
this.findViewById(R.id.pass_cancel).setOnClickListener(this);
this.findViewById(R.id.pass_ok).setOnClickListener(this);
this.findViewById(R.id.password).setOnKeyListener(this);
this.findViewById(R.id.pass_screen).setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.pass_screen) {
this.finish();
return true;
}
else return false;
}
@Override
public void onClick(View v) {
switch(v.getId()){
case(R.id.pass_cancel): this.finish(); break;
case(R.id.pass_ok): checkPass(); break;
}
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() != MotionEvent.ACTION_UP)
return false;
switch(keyCode){
case(KeyEvent.KEYCODE_ENTER):
case(KeyEvent.KEYCODE_DPAD_CENTER): checkPass(); break;
default: return false;
}
return true;
}
private void checkPass(){
if (replace.equals(Util.PASS)){
showMenu(this);
}
else {
((EditText)this.findViewById(R.id.password)).setText("");
Util.getInstance().error("Wrong Password!", this);
}
}
private void showMenu(final Activity act){
Thread t = new Thread(){
public void run(){
act.finish();
act.startActivity(new Intent(act, Menu.class));
}
};
t.start();
}
}
And the other:
public class Menu extends Activity implements OnItemClickListener {
private GridView thumbs;
private ImageAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
adapter = new ImageAdapter(getApplicationContext());
thumbs = (GridView)this.findViewById(R.id.thumbs);
thumbs.setAdapter(adapter);
thumbs.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
((Layout)v).setFocus(true);
setImage(adapter.getItem(position));
}
private void setImage(String pic){
Util.IMAGE_PATH = pic;
Util.SET_IMAGE_FLAG = true;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("IMAGE_PATH", Util.IMAGE_PATH).commit();
this.finish();
}
}
Being unfamiliar with immersive mode, I was hoping some of you might provide the answer.
In your Manifest.xml file add attribute in activity tag
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>