2015-08-15 58 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