Как я могу удалить тень от панели инструментов? - PullRequest
0 голосов
/ 16 ноября 2018

Я хочу удалить тень или строку после имени приложения Когда я помещаю этот код 0dp в XML, я получаю следующую ошибку: недопустимая родительская ссылка 'style / Widget.AppCompat.Light.ActionBar.Solid.Inverse.

1 Ответ

0 голосов
/ 17 ноября 2018

Вам нужно использовать виджет панели инструментов, чтобы установить высоту, аналогичную вашей TabLayout, попробуйте добавить панель инструментов над вашим TabLayout (я использую LinearLayout) следующим образом:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:elevation="4dp"/>

<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    app:tabSelectedTextColor="@android:color/white"
    app:tabTextColor="@android:color/darker_gray"
    app:tabIndicatorColor="@android:color/white"
    app:tabIndicatorHeight="2dp"
    android:elevation="4dp">

    <android.support.design.widget.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RELIGIOUS" />

    <android.support.design.widget.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ANCIENT" />

    <android.support.design.widget.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="MUSEUMS" />

    <android.support.design.widget.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="EVENTS" />
</android.support.design.widget.TabLayout>

также вам нужен новый стиль для удаления панели инструментов по умолчанию, скажем, у нас есть этот новый стиль

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    // this 2 code to remove toolbar and we can use custom toolbar
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

, затем используйте этот стиль для своей деятельности, например:

<activity android:name=".MainActivity"
        android:theme="@style/AppThemeNoActionBar"> // this
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

последний, определите нашу новую панель инструментов в действии.

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(R.string.app_name);

Надеюсь, это поможет:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...