Hide StatusBar/Title on QVGA - Getting Screen Resolution

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Hide StatusBar/Title on QVGA - Getting Screen Resolution

Postby plusminus » Mon Aug 11, 2008 12:11 pm

[align=center]Hide StatusBar/Title on QVGA - Getting Screen Resolution[/align]

What you learn: You will learn how to get the screen-resolution and hide the statusbar on QVGA-reoslutions (or whatever you want).

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     /** Called when the activity is first created. */  
  2.  
  3.     @Override
  4.  
  5.     public void onCreate(Bundle icicle) {
  6.  
  7.         super.onCreate(icicle);
  8.  
  9.        
  10.  
  11.         final Window win = getWindow();
  12.  
  13.         final int screenHeight = win.getWindowManager().getDefaultDisplay().getHeight();
  14.  
  15.         final int screenWidth = win.getWindowManager().getDefaultDisplay().getWidth();
  16.  
  17.        
  18.  
  19.         if((screenHeight == 320 && screenWidth == 240) || (screenHeight == 240 && screenWidth == 320)){
  20.  
  21.              // No Statusbar
  22.  
  23.             win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    
  24.  
  25.  
  26.  
  27.              // No Titlebar
  28.  
  29.              requestWindowFeature(Window.FEATURE_NO_TITLE);
  30.  
  31.              requestWindowFeature(Window.FEATURE_PROGRESS);  
  32.  
  33.         }
  34.  
  35.        
  36.  
  37.         setContentView(R.layout.mylayout);
  38.  
  39.        
  40.  
  41.         //... Your Code here ...
  42.  
  43.     }
Parsed in 0.160 seconds, using GeSHi 1.0.8.4

[align=center]Thats it :)[/align]

Regards,
plusminus
Last edited by plusminus on Thu Sep 18, 2008 8:02 pm, edited 1 time in total.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2696
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby ych.tiger » Mon Aug 18, 2008 1:34 am

Thanks
User avatar
ych.tiger
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jul 08, 2008 4:07 am
Location: China

Postby xMemphisx » Thu Sep 18, 2008 6:30 pm

Update for the 0.9 SDK
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Parsed in 0.127 seconds, using GeSHi 1.0.8.4


The flags changed a bit.
xMemphisx
Developer
Developer
 
Posts: 27
Joined: Wed Jun 25, 2008 12:02 am

Postby plusminus » Thu Sep 18, 2008 8:03 pm

xMemphisx wrote:Update for the 0.9 SDK
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Parsed in 0.140 seconds, using GeSHi 1.0.8.4


The flags changed a bit.


Big thx :)
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2696
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Timmeah » Mon Mar 02, 2009 4:38 pm

Can't see to get this to work. I just want the title and statusbar to be gone in the following code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.panel;
  2.  
  3.  
  4.  
  5. import org.panel.Panel.OnPanelListener;
  6.  
  7. import easing.interpolator.BounceInterpolator;
  8.  
  9. import easing.interpolator.EasingType.Type;
  10.  
  11. import android.app.Activity;
  12.  
  13. import android.os.Bundle;
  14.  
  15. import android.util.Log;
  16.  
  17.  
  18.  
  19. public class Test extends Activity implements OnPanelListener {
  20.  
  21.        
  22.  
  23.         private Panel bottomPanel;
  24.  
  25.         private Panel topPanel;
  26.  
  27.         /** Called when the activity is first created. */
  28.  
  29.     @Override
  30.  
  31.  
  32.  
  33.     public void onCreate(Bundle savedInstanceState) {
  34.  
  35.         super.onCreate(savedInstanceState);
  36.  
  37.        
  38.  
  39.         setContentView(R.layout.main);
  40.  
  41.        
  42.  
  43.         Panel panel;
  44.  
  45.        
  46.  
  47.         topPanel = panel = (Panel) findViewById(R.id.topPanel);
  48.  
  49.         panel.setOnPanelListener(this);
  50.  
  51.         panel.setInterpolator(new BounceInterpolator(Type.OUT));
  52.  
  53.        
  54.  
  55.         bottomPanel = panel = (Panel) findViewById(R.id.bottomPanel);
  56.  
  57.         panel.setOnPanelListener(this);
  58.  
  59.         panel.setInterpolator(new BounceInterpolator(Type.OUT));
  60.  
  61.        
  62.  
  63.     }
  64.  
  65.  
  66.  
  67.         public void onPanelClosed(Panel panel) {
  68.  
  69.                 String panelName = getResources().getResourceEntryName(panel.getId());
  70.  
  71.                 Log.d("Test", "Panel [" + panelName + "] closed");
  72.  
  73.         }
  74.  
  75.         public void onPanelOpened(Panel panel) {
  76.  
  77.                 String panelName = getResources().getResourceEntryName(panel.getId());
  78.  
  79.                 Log.d("Test", "Panel [" + panelName + "] opened");
  80.  
  81.         }
  82.  
  83. }
Parsed in 0.118 seconds, using GeSHi 1.0.8.4



How to do this? Or isn't this possible with
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.main);
Parsed in 0.055 seconds, using GeSHi 1.0.8.4
?
Timmeah
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 10, 2009 4:30 pm

Postby MrSnowflake » Mon Mar 02, 2009 5:00 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.main);
Parsed in 0.054 seconds, using GeSHi 1.0.8.4
Has to be called after you set the flags, as the tut shows...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby Timmeah » Mon Mar 02, 2009 5:09 pm

Ah it works, changed the code, resolution of the Android emulator seems to differ.. ?

I now use the following code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         if(screenHeight > 1 && screenWidth > 1){
  2.  
  3.                // No Statusbar
  4.  
  5.             win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    
  6.  
  7.  
  8.  
  9.                // No Titlebar
  10.  
  11.                requestWindowFeature(Window.FEATURE_NO_TITLE);
  12.  
  13.                requestWindowFeature(Window.FEATURE_PROGRESS);  
  14.  
  15.         }
Parsed in 0.059 seconds, using GeSHi 1.0.8.4
Timmeah
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 10, 2009 4:30 pm

having the opposite problem actually ...

Postby 5tray » Tue May 05, 2009 12:34 am

I'm using a PreferenceActivity to show some preferences, however it seems by default the window title is removed for activities deriving from PreferenceActivity.

Any idea how to re-enable it?
User avatar
5tray
Freshman
Freshman
 
Posts: 3
Joined: Tue May 05, 2009 12:21 am

rgd: having the opposite problem actually

Postby 5tray » Wed May 06, 2009 12:24 am

for the curious: i checked the android source for PreferenceActivity and verified the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     @Override
  2.  
  3.     protected void onCreate(Bundle savedInstanceState) {
  4.  
  5.         super.onCreate(savedInstanceState);
  6.  
  7.  
  8.  
  9.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  10.  
  11.    
  12.  
  13.         setContentView(com.android.internal.R.layout.preference_list_content);
  14.  
  15.        
  16.  
  17.         mPreferenceManager = onCreatePreferenceManager();
  18.  
  19.         getListView().setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
  20.  
  21.     }
  22.  
  23.  
Parsed in 0.064 seconds, using GeSHi 1.0.8.4


And according to the documentation once requestWindowFeature(...) is called for a particular feature, it cannot be undone ... so no title bar for concrete PreferenceActivity's ...

pls correct me if i'm wrong tho :)
User avatar
5tray
Freshman
Freshman
 
Posts: 3
Joined: Tue May 05, 2009 12:21 am

Postby aracos » Wed Feb 17, 2010 1:08 pm

For those of you who like to handle this within an xml file.

Within your theme description you define
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.     <item name="android:windowNoTitle">true</item><!-- The Activity has no title -->
  3.  
  4.     <item name="android:windowFullscreen">true</item> <!-- Hides the Status Bar-->
  5.  
  6.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Within your manifest
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.     <application android:label="@string/app_name"
  3.  
  4.                 android:theme="@style/MyTheme" > <!-- Loads your theme for the complete app -->
  5.  
  6. ...
  7.  
  8.     </application>
  9.  
  10.     <uses-permission android:name="android.permission.STATUS_BAR" /> <!-- necessary to manipulate the status bar-->
  11.  
  12.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4



This way you don't have to bother hiding the bar within every activity of your applicaiton
aracos
Freshman
Freshman
 
Posts: 5
Joined: Tue Feb 02, 2010 1:14 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests