This code causes force close exception on Emulator(API 18) and works in ASUS Nexus 7(API 21)
Also make sure you don't have the background of an imageView set to selectableItemBackgroundBorderless
, otherwise older devices will have this error:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless" />
I was struck with the same problem in the recent app I made. In my case, the problem was I put an image in the folder called drawable-v21, which is not available in older android API.
The solution is to put your drawable in drawable-...dpi folders too.
I think the best way of doing this is, first create a xml file inside the "drawable" folder and do something like below.
e.g. light_gray.xml then do something like below.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
once you have saved it.
change you code like below.
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
But make sure to put the file light_gray.xml only to "drawable" folder. Do not put the same file to "drawable-hdpi or drawable-hdpi-v4 and so on"
It is because my color resource file is under \res\values-21
folder, Now moved it to \res\values\
folder, Now app works fine. thank you friends.
Your color resource must reside in an Android resource file (i.e.: in the colors.xml
file).
Android would not complain where you set it, but it must be defined as a color resource.
I.e.:
<color name="light_gray">#ebebeb</color>
[EDIT]
The names appear not to match...
See this line:
android:background="@drawable/login_btn_selector"
Then you say: So I tried to place the login_btn_selected.xml
.
It seems to be the cause of
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/login_btn_selected.xml from drawable resource ID #0x7f020095.