Android: How to put a solid colored rectangle in the layout?

I have a RelativeLayout that inflates just fine. I would like to add a solid colored rectangle that spans the width of the layout at the top. I tried putting the following in my xml:

<view android:id="@+id/top_alert"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_above="@+id/orders_gridview"
    android:layout_alignParentTop="true"
    android:background="@color/table_request_assistance"
    android:visibility="visible"/>

Now, when I try to inflate my layout, I get a NullPointerException in LayoutInflater.createViewFromTag (line 715):

if (name.equals(TAG_1995)) {

name installed earlier:

if (name.equals("view")) {
    name = attrs.getAttributeValue(null, "class");
}

Obviously, the "class" attribute is missing. How to add this? I can not find anything close at http://schemas.android.com/apk/res/android . Should I add it? Is this the standard way to do this? It seems like it should be the easiest thing in the world.

+4
2

- View, View XML.

+1

noobs . 10- , .

<View android:id="@+id/rectangle_at_the_top"
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:layout_alignParentTop="true"
    android:background="#DDDDDD"
    android:visibility="visible"/>

:

:

android:id="@+id/rectangle_at_the_top"

, , :

android:layout_width="match_parent"

, "fill_parent". "match_parent".

, 10 " :

android:layout_height="10dp"

" "? 100%, : px, dp, dip sp Android?

, . :

android:layout_alignParentTop="true"

, , . - ? , : layout_alignParentTop.

, :

android:background="#DDDDDD"

DDDDDD - . , Google : > Google Android

, , :

android:visibility="visible"

, . "" "", , . . : "" "?"

+1

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


All Articles