1

I have the following element

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/black_border"> 

And black_border is:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <stroke android:width="1px" android:color="#000"/> </shape> 

The desired result is a 1px black border around the elements inside the LinearLayout.

On my device (running 5.0/Level 21) everything looks good, the contents of that element are grouped by a 1px black border.

However, the min sdk my app will support is level 10/2.3 and when I run the app in the emulator the whole background of the LinearLayout is black. It seems like it is treating the stroke as a fill.

Has anyone come across this?

Edit: I gave the black_border a stroke of white, this somewhat solved my problem. TextViews inside the LinearLayout had no visible border with this change, so a subsequent step was needed to give them a border.

2 Answers 2

1

I had the same issue with api level 9. You have to explicity tell that the solid is transparent.

Try this:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <stroke android:color="@color/colorPrimaryDark" android:width="2dp" android:height="2dp"/> <solid android:color="@color/trasparent" android:width="2dp" android:height="2dp"/> <size android:width="10dp" android:height="10dp"/> </shape> 

where colorPrimaryDark is defined as black (#FF000000) and transparent is #00000000

I suggest you to use dp for dimensions instead of px.

Sign up to request clarification or add additional context in comments.

1 Comment

I used the same solution ;)
0

I got round this by giving black_border a stroke of white. Subsequently I needed to give any TextViews inside the LinearLayout a border as having a white background made them borderless.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.