2016-09-05 22 views
1

這裏是我的ActionBar相關的代碼:如何隱藏我的動作條

ActionBar actionBar = getSupportActionBar(); 
    actionBar.setTitle(R.string.app_name); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorTextHint))); 

    actionBar.setDisplayShowHomeEnabled(true); // To Show the Home Icon 
    actionBar.setHomeButtonEnabled(false); // To get the click Event of the 
    // Home Button 
    actionBar.setDisplayHomeAsUpEnabled(true); // To Unable Home Button to 
    // work as a Navigation 
    // Drawer Opener. 

    pager = (ViewPager) findViewById(R.id.viewPager); 
    pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager())); 

    for (String tab_name : tabs) 
    { 
     actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this)); 
    } 

    actionBar.setSelectedNavigationItem(0); 

我得到這個ActionBar

I'm getting this

但我想只有這部分是我的ActionBar

enter image description here

預先感謝您的幫助&建議。

+0

使用一個'Toolbar'作爲'ActionBar'並且放入任何你想要的東西。 – earthw0rmjim

回答

0

使用這兩條線

actionBar.setDisplayShowHomeEnabled(false);    
actionBar.setDisplayShowTitleEnabled(false); 

代替

actionBar.setDisplayShowHomeEnabled(true); 
actionBar.setHomeButtonEnabled(false); 
actionBar.setDisplayHomeAsUpEnabled(true); 

爲我工作!

0

您可以使用自定義視圖操作欄

Toolbar toolbar = (Toolbar) findViewById(R.id.'id of custom layout'); 
setActionBar(toolbar); 
+0

這不是一個答案。請仔細閱讀問題,然後回答。問題標題雖然有點混亂。 –

0

我已經改變了問題的標題作爲問題不是關於如何使用定製ActionBar,而它指向隱藏ActionBar

這樣做的優雅方式是在AndroidManifest.xml文件中設置Activity的主題。

因此,您在清單中的Activity聲明應該如下所示。

<activity 
    android:name=".Activities.YourActivity" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme.NoActionBar" /> 

樣式如下。把這個在您的res/values/styles.xml

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

而且同一風格的其它變種內res/values-v21/styles.xml

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
</style> 

希望幫助!