-2

I am inserting custom view inside a relative layout. The action bar turning into white color Here is the xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/dark_tablet_converted"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <com.test.myview
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="8dp" />

    <TextView
        android:id="@+id/text1"
        style="?android:attr/listSeparatorTextViewStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:gravity="center_horizontal"
        android:text="text : "
        android:textSize="15sp"
        android:textStyle="bold" />


</RelativeLayout>

and here is the image.

TextView without custom view

CustomView with TextView

I am not getting where is the problem.

Android support library used

'android support appcompat-v7:23.0.1'
'android.support v4:23.0.1'
targetSdkVersion 23
compileSdkVersion 23
buildToolsVersion '23.0.1'

EDIT: Whatever placed above my view will get displayed. only if any layout/view is placed below my customview will get vanished.

Madhukar Hebbar
  • 3,113
  • 5
  • 41
  • 69

2 Answers2

0

your views are child of relative layout so, they are drawed one on the other and you can't really decide who will be in foreground and who will be in background

add a framelayout as parent of your custom and text view then, in your code, find your textview and call "bringToFront"

Jerome B.
  • 244
  • 2
  • 8
0

try this,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/dark_tablet_converted"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <com.test.myview
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true"
        android:layout_gravity="center"
        android:padding="8dp" />

    <TextView
        android:id="@+id/text1"
        style="?android:attr/listSeparatorTextViewStyle"
        android:layout_below="@+id/view"
        android:layout_width="match_parent"
        android:layout_marginTop="10dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:gravity="center_horizontal"
        android:text="text : "
        android:textSize="15sp"
        android:textStyle="bold" />
</RelativeLayout>
Ganpat Kaliya
  • 888
  • 2
  • 9
  • 16