2016-08-25 81 views
7

我正在編寫一個應用程序,它將在嵌入式設備上,我需要刪除標題欄和ContentOverlay旁邊的ActionBar。 我找到了解決辦法,並插在我的風格如下:WindowActivityBar = false不工作

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light"> 
     <item name="android:windowActionBar">false</item> 
     <item name="android:windowNoTitle">true</item> 
     <item name="android:windowFullscreen">true</item> 
     <item name="android:windowContentOverlay">@null</item> 
</style> 

,並添加一行到我的活動AndroidManifest:

android:theme="@style/NoActionBar" 

,並在最後我沒有標題欄,沒有內容疊加,但是ActionBar仍然存在。請指教。我用android:theme="@android:style/Theme.Holo.Light"和我targetSdkVersion爲18

+0

通過設置Action Bar false,您只需禁用操作欄,因此您需要通過在活動java文件中編寫以下代碼來隱藏它,以隱藏它。 getWindow()。requestFeature(Window.FEATURE_ACTION_BAR); getActionBar()。hide(); 這應該在setContentView()之前的頂部。 – Vickyexpert

+0

但是在我的活動中,Action Bar仍然正常工作。 –

+0

你明確設置工具欄嗎?在你的活動? – Elltz

回答

1

在XML小錯誤可能會導致非常奇怪的問題,
這些並不總是由構建過程準確報告。
我傾向於改變XML,當我可以在java中完成時。
Java給你更多的控制。

programmatically remove action bar 
---------------------------------- 
from normal activity 

getActionbar().hide(); 
getActionbar().show(); 

if your using support activity 

getSupportActionBar().hide(); 
getSupportActionBar().show(); 

and from the Fragment you can do it 

getActivity().getActionbar().hide(); 
getActivity().getActionbar().show(); 

remove title bar 
---------------- 

public class ActivityName extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // remove title 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.main); 
    } 
} 

ActionBar ContentOverlay 
------------------------ 
1) Request for actionbar overlay programmatically by calling 

     getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 

// this 'requestFeature()' must be requested from your activity 'onCreate()' method 
// before calling for 'setContentView(R.layout.my_layout)': 
2) set the actionbar color by calling setBackgroundDrawable() like so: 
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00212121"))); 
-1

試着改變你的風格的父母是這樣的:

parent="@android:style/Theme.Holo.Light.NoActionBar" 

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light.NoActionBar"> 
    <item name="android:windowActionBar">false</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 

+0

也沒有幫助: –