Android view border question.

Asked 2 years ago, Updated 2 years ago, 161 views

This is shape_list.xml.

<?xml version="1.0" encoding="utf-8"?> <!--Output shape square-->

<solid android:color="#ffffff"  />
<!--Output color to shape -->
<stroke
    android:width="10dp"
    android:color="#1a0707">
</stroke>

<!--Make sure to write > at the end of each attribute. Otherwise, </appropriate properties> will not be written.-->

</shape>

This is activity_main.xml <?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/textView"
    android:layout_width="238dp"
    android:layout_height="93dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_weight="0.81"
    android:text="University Image"
    android:textAlignment="center"
    android:textSize="30sp"
    android:typeface="sans"
    tools:layout_editor_absoluteX="73dp"
    tools:layout_editor_absoluteY="62dp"
    android:background="@drawable/shape_list"/>

<Button
    android:id="@+id/button"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:text="School"
    android:clickable="true"
    android:onClick="school"
    tools:layout_editor_absoluteX="67dp"
    tools:layout_editor_absoluteY="343dp" />

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textMultiLine"
    android:text="school year"
    tools:layout_editor_absoluteX="85dp"
    tools:layout_editor_absoluteY="189dp" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textMultiLine"
    android:text="Department"
    tools:layout_editor_absoluteX="84dp"
    tools:layout_editor_absoluteY="233dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:text="Activity-Back"
    android:clickable="true"
    android:onClick="activity_back"
    tools:layout_editor_absoluteX="67dp"
    tools:layout_editor_absoluteY="391dp" />

<Button
    android:id="@+id/button3"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:text="Activity-Main"
    android:clickable="true"
    android:onClick="activity_main"
    tools:layout_editor_absoluteX="67dp"
    tools:layout_editor_absoluteY="447dp" />

It looks like this, but I'm going to give you a border to go to TextView University. So I made shape_list.xml, which is about the border, and gave "@drawable/shape_list" to the background of the view, but when I looked at the design, the border did not appear.I checked the border color, and I changed the solid color from white to another color, but the border still doesn't appear. Where did I make a mistake?

android view background xml

2022-09-22 13:54

1 Answers

I can't tell if the shape_list.xml code you posted was copied and copied wrong or written wrong. First of all, make sure that the code is written as follows.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid
        android:color="#ffffff"/>
    <stroke
        android:width="10dp"
        android:color="#1a0707"/>
</shape>

Additionally, check if it doesn't appear on the design screen of the Android studio or on the actual app.


2022-09-22 13:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.