2015-08-15 59 views
0

我正在開發一個android應用程序。我能夠將使用支持庫的工具欄添加到應用程序中。現在我想添加標籤到應用程序。但該標籤應該是不可滑動的。我搜索了互聯網,但所有的問題和文章都是用於滑動標籤。在Android中添加不可滑動的Tab到工具欄

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

<android.support.v7.widget.Toolbar 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbarsdfs" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimaryDark" 
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar"> 

</android.support.v7.widget.Toolbar> 

</LinearLayout> 

ToolbarActivty.Java

public class ToolbarActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.toolbar); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarsdfs); 
    if (toolbar != null) { 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    } 
} 
} 

這是我想acheive。 enter image description here

+0

你有沒有得到任何解決方案呢? –

+1

是的。我在我的代碼的工具欄下添加了TabLayout,併爲活動中的選項卡提供了片段。 – Faiyaz

+1

酷..快樂編碼:) –

回答

0

如果你不使用滑動式標籤試圖通過使用custome Tabhoast標籤。但最簡單的是添加按鈕,並按下按鈕點擊上面的片段。

+0

你能把我重定向到一篇文章或樣本嗎? – Faiyaz

+0

http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html請看看 – Nivedh

+0

https://maxalley.wordpress.com/2013/05/18/android-creating-a -tab-layout-with-fragmenttabhost-and-fragments/ – Nivedh