有時候想呈現繪圖背景或是想播放Video影像時 , 會想在狹小的螢幕多爭取一點空間
這時候乾脆就把Title Bar和Notification Bar隱藏獲取更多螢幕空間吧!!!! 步驟很簡單
先看下面的圖片 , 這時候Title Bar和Notification Bar都還在
接下來為了要隱藏Title Bar這邊有幾個方法 , 首先可以在AndroidMenifest.xml , 在對Activity 作屬性定義的時候可以加上 android:theme 來設置 Activity 的主題
仔細看可以發現 AndroidMenifest.xml多了兩行註解
<!-- android:theme="@style/myThemeOne" -->
<!-- android:theme="@style/myThemeTwo" -->
這是我們自定義的style , 使用他們來替換都可以得到一樣的效果 , 而style Resource是要放置在res/values下的 , 可以參考這邊 , 在這邊我把
@style/myThemeOne放在原本的string.xml檔案裡
android:theme="@style/myThemeTwo放在style.xml裡 , 但是都必須放在res/values下
Hello World, Test ThereIsTitleBar
成功之後就會出現下圖的結果
如果說還想把Notification Bar隱藏的話 , 只要加上這段程式碼
public class NoTitleBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
//這行程式碼也可以隱藏Title Bar但是位置要放對
setContentView(R.layout.main);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
成功之後如下
連Notification Bar都消失了
其實想達到同樣的效果還可以這樣 , 在AndroidMenifest.xml 替Activity Theme這個定義
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
另外下面這篇文章對於 Android提供的Theme資料整理的很詳細 , 很棒



沒有留言:
張貼留言