视图在运行时不起作用的立面阴影

时间:2018-07-20 14:27:54

标签: android android-layout elevation android-elevation

我知道这个问题已经问了很多遍了,但是我尝试了所有问题,我已经解决了3天了。

我有一个带有导航抽屉的baseActivity.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/activity_base_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:background="@drawable/shape_container_color_primary"
    android:fitsSystemWindows="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:background="@drawable/shape_container_color_primary">

        <FrameLayout
            android:id="@+id/activity_base_content_frame"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@id/activity_base_toolbar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"></FrameLayout>

        <android.support.constraint.ConstraintLayout
            android:id="@+id/activity_base_toolbar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/shape_container_color_primary"
            android:elevation="40dp"
            android:padding="2dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/activity_base_content_frame">


            <Button
                android:id="@+id/activity_base_menu_button"
                android:layout_width="26dp"
                android:layout_height="26dp"
                android:background="@drawable/icon_menu"
                android:layout_marginBottom="15dp"
                android:layout_marginEnd="25dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@id/activity_base_home_button"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/activity_base_menu_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/activity_base_menu"
                android:textColor="@color/ColorWhite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@id/activity_base_menu_button"
                app:layout_constraintStart_toStartOf="@id/activity_base_menu_button"
                app:layout_constraintTop_toBottomOf="@id/activity_base_menu_button" />

            <Button
                android:id="@+id/activity_base_home_button"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/icon_home"
                android:layout_marginBottom="15dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/activity_base_home_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/activity_base_home"
                android:textColor="@color/ColorWhite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@id/activity_base_home_button"
                app:layout_constraintStart_toStartOf="@id/activity_base_home_button"
                app:layout_constraintTop_toBottomOf="@id/activity_base_home_button" />

            <Button
                android:id="@+id/activity_base_news_button"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/icon_news"
                android:layout_marginBottom="15dp"
                android:layout_marginStart="25dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/activity_base_home_button"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/activity_base_inventory_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/activity_base_news"
                android:textColor="@color/ColorWhite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@id/activity_base_news_button"
                app:layout_constraintStart_toStartOf="@id/activity_base_news_button"
                app:layout_constraintTop_toBottomOf="@id/activity_base_news_button" />
        </android.support.constraint.ConstraintLayout>


    </android.support.constraint.ConstraintLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/activity_base_content_nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/menu_main_header"
        app:menu="@menu/menu_main" />
</android.support.v4.widget.DrawerLayout>

由于我需要所有活动都具有相同的菜单和工具栏,因此我的BaseActivity.java中具有以下方法:

    @Override
public void setContentView(int layoutResID) {
    final DrawerLayout fullView = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
    FrameLayout activityContainer = fullView.findViewById(R.id.activity_base_content_frame);
    getLayoutInflater().inflate(layoutResID, activityContainer, true);
    super.setContentView(fullView);
    final NavigationView navigationView = fullView.findViewById(R.id.activity_base_content_nav_view);
    navigationView.setNavigationItemSelectedListener(item -> {
        switch (item.getItemId()) {
            case R.id.menu_main_settings:
                final Intent settingsIntent = new Intent(BaseActivity.this, SettingsActivity.class);
                startActivity(settingsIntent);
                this.finish();
                break;
            case R.id.menu_main_my_account:
                final Intent accountIntent = new Intent(BaseActivity.this, AccountActivity.class);
                startActivity(accountIntent);
                this.finish();
                break;
            case R.id.menu_main_logout:
                this.openAlertDialog(LOGOUT, AlertDialogType.ALERT_LOGOUT);
                break;
        }
        return true;
    });
    this.mDrawerLayout = findViewById(R.id.activity_base_drawer_layout);
    final View hView = navigationView.getHeaderView(0);
    this.mPlayerProfilPicture = hView.findViewById(R.id.menu_main_header_user_picture);
    this.mPlayerNicknameTextView = hView.findViewById(R.id.menu_main_header_nickname_text);
    this.mPlayerLevelTextView = hView.findViewById(R.id.menu_main_header_level_text);
    this.mBaseViewModel = ViewModelProviders.of(this, this.vmFactory).get(BaseViewModel.class);
    final String currentPlayerGoogleId = SharedSettingsHelper.getGoogleSignInId();
    this.mBaseViewModel.init(currentPlayerGoogleId);
    this.observeViewModel(this.mBaseViewModel);

}

问题是下一个问题:我可以在Android Studio预览上看到高程阴影,但在运行时看不到: 预览哪些阴影可见:
preview on which shadow is visible

但是在我的设备(或仿真器)上,没有任何阴影...

0 个答案:

没有答案