java - How do I hide or show layout elements when an Android Activity goes out of focus? -


i trying hide elements in layout when android goes out of focus, such when viewed in "view recent applications" display, layout elements not visible. upon selecting application , going focus, these elements visible again.

my implementation below attempts show "content" layout when application in focus, , show "overlay" layout when out of focus, via onwindowfocuschanged().

activity_main.xml

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/container"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".mainactivity">     <relativelayout         android:id="@+id/content"         android:layout_width="match_parent"         android:layout_height="match_parent">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="this content page"/>     </relativelayout>     <relativelayout         android:id="@+id/overlay"         android:layout_width="match_parent"         android:layout_height="match_parent">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="this overlay"/>     </relativelayout> </framelayout> 

mainactivity.java

public class mainactivity extends actionbaractivity {      framelayout layoutcontainer;     relativelayout layoutcontent;     relativelayout layoutoverlay;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          layoutcontainer = (framelayout) findviewbyid(r.id.container);         layoutcontent = (relativelayout) findviewbyid(r.id.content);         layoutoverlay = (relativelayout) findviewbyid(r.id.overlay);      }      @override     public void onwindowfocuschanged(boolean hasfocus) {          if (hasfocus) {             layoutcontent.setvisibility(view.visible);             layoutoverlay.setvisibility(view.gone);         } else {             layoutoverlay.setvisibility(view.visible);             layoutcontent.setvisibility(view.gone);         }      } } enter code here 

however, implementation not work. suggestion solve this? thanks!

if want hide views in layout in recent apps try this

getwindow().setflags(windowmanager.layoutparams.flag_secure,windowmanager.layoutparams.flag_secure); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -