【发布时间】:2015-12-14 22:44:45
【问题描述】:
我在这里查看了很多与工具栏相关的答案,但没有一个答案可以帮助我。
我想要实现的是有一个扩展的工具栏,它将显示一个徽标和菜单项。
我试图实现这一点的方式是通过工具栏。首先,我创建工具栏并添加我的自定义视图。
我的toolbar.xml:-
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dl_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
android:clipToPadding="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize">
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#358c44"
android:layout_alignParentTop="true"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="#358c44"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
我的名字活动:-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
toolbar.setLogo(R.mipmap.ic_launcher);
/* toolbar.setPadding(10,10,10,10);*/
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(true);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
我的应用显示如下:-
我是android开发新手,请帮助我!提前致谢
更新我的代码后,我的应用看起来像:-
【问题讨论】:
-
您想在标签更改时更新工具栏吗?
-
不不,我只想让绿线占据整个屏幕宽度。
-
设置工具栏高度为 android:layout_height="?attr/actionBarSize"
-
我试过但没有成功。