0
我一直在嘗試使用新的設計庫,我有一個工具欄而不是棄用的操作欄。問題是工具欄沒有標高。我在佈局中添加了海拔高度,在代碼中,我甚至添加了AppBarLayout。什麼都沒有我正在測試棒棒糖和奇巧。爲什麼工具欄沒有提升?
任何幫助,高度讚賞。
我style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<!-- Customize your theme here. -->
</style>
</resources>
activity_main.xml中
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:elevation="7dp"
android:id="@+id/tool_bar"
layout="@layout/app_bar"
></include>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_draw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>
主要活動:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
Toolbar toolbar;
View root;
NavigationView nav_draw;
DrawerLayout drawer_layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupToolbar();
drawer_layout = (DrawerLayout)findViewById(R.id.drawer_layout);
nav_draw = (NavigationView) findViewById(R.id.nav_draw);
nav_draw.setNavigationItemSelectedListener(this);
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new Fragment())
.commit();
}
private void setupToolbar(){
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setElevation(18);
final ActionBar ab = getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
ab.setDisplayHomeAsUpEnabled(true);
}
}
app_bar佈局文件
<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/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="7dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
您使用的是什麼版本的SDK?如果你想在Pre Lollipop sdk上升高,你應該選中這個:http://blog.grafixartist.com/add-a-toolbar-elevation-on-pre-lollipop/或者這個:http://stackoverflow.com/questions/ 26743325/appcompat-v21-toolbar-elevation-pre-lollipop –
對於預棒棒糖設備,高程屬性不起作用。您可能需要在工具欄下方添加自定義陰影視圖。 –
sdk version:23 de [endencies:compile'com.android.support:appcompat-v7:23.0.1' compile'com.android.support:design:22.2.0' – Tina