0

I am trying to override home key and full screen the acitiy using below code. locking of home key is working fine but it unable to hide notification bar (unable to full screen the activity).

public class ScreenLockDemo extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screenlock);

    }



@Override
public void onAttachedToWindow()
{  
  this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();  

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if(keyCode==KeyEvent.KEYCODE_BACK){
        return true;
    }
    if(keyCode==KeyEvent.KEYCODE_HOME){
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

}

AndroidManifest.xml :

 <activity
        android:name="com.antivirus.antitheft.ScreenLockDemo"
         android:configChanges="touchscreen|keyboard|keyboardHidden|navigation|orientation"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
       >              
    </activity>

![out put of above code it cute the topside of layout as show in img. ][1]

i am also trying to setType using handler it full screen the activity but it could not override menu key. please help me.

Thanks in advance.

Prashant Kadam
  • 1,207
  • 4
  • 18
  • 30

4 Answers4

0

The easiest solution to set the activity as full screen is to set it in the manifest. As an example add the following to your activity section within the manifest:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Therefore it should look something like:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".blahActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
ASceresini
  • 419
  • 3
  • 7
  • i already use this code but its not work in the case of public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); } this method – Prashant Kadam Apr 27 '12 at 09:01
0

Solve Problem using below code

@Override
 public void onAttachedToWindow() {
  // TODO Auto-generated method stub
     super.onAttachedToWindow();  

     handler.postDelayed(mUpdateUiMsg, 100);
    //this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);     
 }


 public boolean onKeyDown(int keyCode, KeyEvent event) {
  // TODO Auto-generated method stub
  if(keyCode==KeyEvent.KEYCODE_BACK){
   return true;
  }
  if(keyCode==KeyEvent.KEYCODE_HOME){
   return true;
  }

  return super.onKeyDown(keyCode, event);
 }


 private Runnable mUpdateUiMsg = new Runnable() {
        public void run() {


            getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);


         }
    };
Prashant Kadam
  • 1,207
  • 4
  • 18
  • 30
0

Solve Problem using below code

@Override
 public void onAttachedToWindow() {
  // TODO Auto-generated method stub
     super.onAttachedToWindow();  

     handler.postDelayed(mUpdateUiMsg, 100);
    //this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);     
 }


 public boolean onKeyDown(int keyCode, KeyEvent event) {
  // TODO Auto-generated method stub
  if(keyCode==KeyEvent.KEYCODE_BACK){
   return true;
  }
  if(keyCode==KeyEvent.KEYCODE_HOME){
   return true;
  }

  return super.onKeyDown(keyCode, event);
 }


 private Runnable mUpdateUiMsg = new Runnable() {
        public void run() {


            getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);


         }
    };

In my case,after overridding onAttachedToWindow(),i found overridePendingTransition(int enterAnim, int exitAnim) or

<style name="Theme.NoTitleBar.WithColoredSpinners" parent="@android:style/Theme.NoTitleBar">
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
    <item name="android:windowAnimationStyle">@style/AnimationActivity</item>
</style>

Did not work, but problem was solved using these code, but I don't know why yet. And the same, I don't know the method onAttachedToWindow() what to do and how it effects?

biegleux
  • 13,179
  • 11
  • 45
  • 52
chiefhsing
  • 11
  • 2
-1

Try this code before setContentView(xml)

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Hope, this will work for you.

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • i am trying this code but Not working it cut topside to layout... the above code is not work when i use public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); } this method in my code to override the menu key. – Prashant Kadam Apr 27 '12 at 08:57
  • Had you tried this code, you would have discovered that it doesn't work. You don't get the full screen. – Johann Aug 25 '13 at 07:02