Как установить цвет фона Android на фрагменты - PullRequest
0 голосов
/ 25 июня 2019

У меня есть фрагмент активности с WebView и TextView.

enter image description here

Здесь вы можете видеть 2 цвета фона.Цвет фона WebView - белый, а цвет остальных частей (я выделил их черными прямоугольниками) - серый.Я думаю, что это стандартный цвет Light Theme, и я хочу изменить его на белый (как в WebView). Я пытался сделать много вещей: android: background в Layout Layout и Activity Layout, я пытался

<item name="android:windowBackground">@color/backgroundColor</item> в разделе Активность и приложение.

Как установить цвет фона на белый?

Код фрагмента:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginStart="15dp"
    android:layout_marginEnd="15dp"
    android:background="@color/backgroundColor"
    android:orientation="vertical"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <WebView
            android:id="@+id/wb_for_task"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"></WebView>

        <TextView
            android:id="@+id/tv_in_task_informatics"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>

Код активности:

<android.support.v4.widget.DrawerLayout 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:background="@color/backgroundColor"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/CoolTheme"
    tools:context=".activities.MainActivity"
    tools:openDrawer="start">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgroundColor"
        android:orientation="vertical">

        <include
            android:id="@+id/app_bar_in_main"
            layout="@layout/app_bar" />

        <FrameLayout
            android:background="@color/backgroundColor"
            android:id="@+id/container_in_Main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></FrameLayout>
    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_viewInMain"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#FFFF"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>

Темы (первая - AppTheme):

<style name="CustomToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:background">@color/colorPrimary</item>
        <item name="android:windowBackground">@color/backgroundColor</item>
        <item name="elevation">0dp</item>
    </style>
    <style name="CoolTheme" parent="Theme.AppCompat.Light">
        <item name="android:background">@color/backgroundColor</item>
        <item name="android:windowBackground">@color/backgroundColor</item>
    </style>

Ответы [ 2 ]

1 голос
/ 25 июня 2019

Ваша тема не применяется. Установите его в файле манифеста на уровне приложения или активности:

 <activity android:name=".MainActivity"
            android:theme="@style/CoolTheme">

Ваше окно прокрутки имеет поля слева и справа, где виден фон фрагмента. Для просмотра прокрутки следует использовать отступы вместо полей.

Ссылка: https://developer.android.com/guide/topics/ui/look-and-feel/themes

0 голосов
/ 25 июня 2019

Просто добавьте отступ вместо margin в ScrollView в вашем фрагменте.

Вот измененный код:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingStart="15dp"
    android:paddingEnd="15dp"
    android:background="@color/backgroundColor"
    android:orientation="vertical"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <WebView
            android:id="@+id/wb_for_task"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"></WebView>

        <TextView
            android:id="@+id/tv_in_task_informatics"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...