Android - changing the background color of a field

I have a fragment with a name HostFragmentthat contains from one to four other fragments.

This is the layout HostFragment:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hostFragmentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="12dp">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <RelativeLayout
            android:id="@+id/fragmentContainer1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"/>

        <RelativeLayout
            android:id="@+id/fragmentContainer2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"/>

    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <RelativeLayout
            android:id="@+id/fragmentContainer3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"/>

        <RelativeLayout
            android:id="@+id/fragmentContainer4"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"/>

    </TableRow>

</TableLayout>

An important part of this is android:layout_marginTop="12dp".

Background: Nested fragments cover everything HostFragmentexcept this field. When nested fragments change their background color (causing Canvas#drawColor), HostFragmentyou must also change the color of this field to match. I keep the necessary color in SharedPreferences.

: HostFragment SettingsActivity, HostFragment, ( onResume()), HostFragment - . HostFragment , HostFragment, . , - HostFragment, . HostFragment .

: , onResume() - mTableLayout.setBackgroundColor(...) mView.setBackgroundColor(...) (mView - onCreateView()). , , .

: , int SharedPreferences, HostFragment Activity (.. )?

!

+4
5

paddingTop marginTop, onResume mView.setBackgroundColor(...).

  • - , .
  • - , , , .
+5

. - , .

1) . , - . , , , .

2) . , . . ( ) . fooobar.com/questions/43483/....

, , .. . http://www.w3schools.com/css/css_boxmodel.asp. - CSS, , .

+1

.setBackgroundColor(...), onResume(), , , , - , . . , FrameLayout, TableLayout, TableLayout . FrameLayout, .

TableLayout, , HostFragment, . HostFragment FrameLayout, - TableLayout. FrameLayout.

image: http://oi59.tinypic.com/jz8q46.jpg

0

,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/c1_cnxlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black" >

    <RelativeLayout 
        android:id="@+id/c2_cnxlayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:background="@android:color/darker_gray" />

</RelativeLayout>
0

- , , .

0

Source: https://habr.com/ru/post/1607742/


All Articles