Layout background color disappears on runtime

戏子无情 提交于 2019-12-08 11:28:12

问题


I'm trying to create a trimmer bar to my video player, on design time it's everything ok but on runtime the background color of my bar disappears

trimmer_bar:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/thumbsBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"
        tools:background="#ab5442">


        <ImageView
            android:id="@+id/leftThumb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription=""
            android:scaleType="fitStart"
            android:src="@drawable/ic_left_thumb" />


        <ImageView
            android:id="@+id/rightThumb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:contentDescription=""
            android:scaleType="fitEnd"
            android:src="@drawable/ic_right_thumb" />


    </RelativeLayout>

    <ImageView
        android:id="@+id/progressIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerVertical="true"
        android:layout_marginStart="60dp"

        android:contentDescription=""
        android:src="@android:drawable/btn_star_big_on" />

</RelativeLayout>

main_activity:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".activities.Main2Activity"
    android:orientation="vertical">


    <com.tomatedigital.instagram.longstories.ui.TrimmerBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


    </com.tomatedigital.instagram.longstories.ui.TrimmerBar>

</LinearLayout>

i cannot paste the whole code of trimmerbar.java here because it's too long as it keeps the video progress synchronized between the bar and the player... but i've searched EVERYWHERE, none of my class has any mention to setBackground or related the only layout field i handle are the margins


回答1:


You set tools:background="#ab5442"(It setting just for preview), for setting backgroun in runtime set android:background="#ab5442" tools namespace just for convinience when developing and not affecting runtime



来源:https://stackoverflow.com/questions/50358393/layout-background-color-disappears-on-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!