Vector drawables not loading in xml ResourceNotFoundException - java

I am having trouble with loading vector files in my splash background xml file. The vector has been loaded successfully because I can open the vector file in android studio and I get a small graphic of the vector on the side of the xml file. However, the design view of the xml file shows an error for the vector file, and I get a ResourceNotFoundException when trying to run my app.
Code below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorPrimary"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/ic_loading_screen_logo"/>
</item>
</layer-list>
splash background.xml
My grade version is classpath 'com.android.tools.build:gradle:4.0.1'
and I have included the following line in my grade app file vectorDrawables.useSupportLibrary = true
It seems that any vector file that I use has this error, so there is some setting of some sort that is missing.
Please assist in anyway.
Thanks,

The problem is wrapping the xml drawable in a <bitmap/>
Try this:
Replace
<item>
<bitmap
android:gravity="center"
android:src="#drawable/ic_loading_screen_logo"/>
</item>
With:
<item android:gravity="center"
android:drawable="#drawable/ic_loading_screen_logo"/>

replace <bitmap to <item
make sure that your vector is in drawable folder not in drawable-24.
check vectory path may be its too long.

Related

How to change app:elevation programmatically

My app is work for API 19. So I can't use android:elevation. So I app:elevation in my layout.
Android XML: android:elevation vs. app:elevation
For exemple :
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="5dp">
How to change app:elevation programmatically ? I can change android:elevation but I can't find how to change app:elevation !
Try with using the following code
ViewCompat.setElevation(View, float)
Following the below link. Here showed how to make elevation on pre-lollipop device
Android AppCompat 21 Elevation
The accepted answer won't actually work. The answer should have been updated.
If you look at why mAppBarLayout.setTargetElevation(0) is deprecated. it states that:
#deprecated target elevation is now deprecated.
AppBarLayout's elevation is now controlled via a {#link android.animation.StateListAnimator}.
This method now always returns 0.
So to programmatically set the appbar layout you can only do it by creating a StateListAnimator such as appbar_state_unelevated_animator at the animator res folder:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<objectAnimator
android:propertyName="elevation"
android:valueTo="4dp"
android:valueType="floatType"
android:duration="100"/>
</item>
then loading it in code like so:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appbar.stateListAnimator = AnimatorInflater.loadStateListAnimator(applicationContext, R.animator.appbar_state_unelevated_animator)
}
If I'm not mistaken you could also create a StateListAnimator by code but don't take my word for it.
Update:
In my experience when you set the
app:elevation="//Any DP value//"
The Shadow of the app bar will be lost. Simple remove that line to get the appbar shadow again.
I would like to provide updated and full answer:
switch (state) {
case On:
appBarLayout.setStateListAnimator(AnimatorInflater.loadStateListAnimator(getContext(), R.animator.appbar_elevation_on));
break;
case Off:
appBarLayout.setStateListAnimator(AnimatorInflater.loadStateListAnimator(getContext(), R.animator.appbar_elevation_off));
break;
}
appbar_elevation_on.xml under RES\animator
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="PrivateResource">
<item>
<objectAnimator
android:propertyName="elevation"
android:valueTo="#dimen/design_appbar_elevation"
android:valueType="floatType" />
</item>
</selector>
appbar_elevation_off.xml under RES\animator
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="PrivateResource">
<item>
<objectAnimator
android:propertyName="elevation"
android:valueTo="0dp"
android:valueType="floatType" />
</item>
</selector>
Since you try to change the elevation of the Action bar you can easily use this line, which will work on API 19
getSupportActionBar().setElevation(0);
or you follow this link and check out how to change the elevation of views on Android below API 21 generally
Android AppCompat 21 Elevation
Accepted answer didn't work for me.
To remove shadow in Toolbar use
app:elevation="0" in AppBarLayout xml or
use mAppBarLayout.setTargetElevation(0) in java.
It worked in my case.
The following solution is for NativeScript
let nativeAnView = tnsView.android;
var shape = new android.graphics.drawable.GradientDrawable();
shape.setShape(android.graphics.drawable.GradientDrawable.OVAL);
shape.setColor(android.graphics.Color.parseColor('#30bcff'));
nativeAnView.setBackgroundDrawable(shape);
nativeAnView.setElevation(20);
on Android
let nativeView = tnsView.ios;
nativeView.layer.shadowColor = new Color('#888888').ios.CGColor;
nativeView.layer.shadowOffset = CGSizeMake(0, 2.0);
nativeView.layer.shadowOpacity = 0.5;
nativeView.layer.shadowRadius = 5.0;
on iOS

Scaling ImageButton for various screen sizes

After scaling the image I use for my ImageButton with the Nine-patch Generator to retrieve all of the dpi files as well as maintaining the appropriate ".9" extensions, and referenced the bitmap in the src of the button, I still get the following result with the Nexus 5 virtual emulator (1080X1920, xxhdpi):
... There's no way in hell that the ImageButtons are 227X53 pixels (xxhdpi) here... But rather, the system retrieves a lower dpi like mdpi instead.
Here's the XML code for just one of the buttons:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/demosBtn"
android:src="#drawable/demo_btn"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#android:color/transparent" />
And as for the drawable resource file of the demo button:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/pressed_demo" android:state_pressed="true"/>
<item android:drawable="#drawable/norm_demo"/>
</selector>
P.S. I tried this with ImageView as well, set it as clickable, set adjustViewBounds to true, and set scaleType to centerCrop, and yet it didn't work.
Use SVG (Scalable vector graphics)! You can scale them to any resolution and they still look super HD. :D

Android not recognizing string resource

In my android app, I have a string
<string name="action_upload">Upload Image</string>
in the strings file. Then in a menu file I have
navigation_screen.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="android.arin.NavigationScreen" >
<item
android:id="#+id/action_upload"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_upload"/>
<item
android:id="#+id/action_forward"
android:icon="#drawable/ic_action_forward"
android:title="#string/action_forward"
android:showAsAction="ifRoom" />
</menu>
However when I try to run it, I get an error saying:
[2014-06-19 17:26:18 - ARIN] W/ResourceType( 9060): ResXMLTree_node size 0 is smaller than header size 0x100.
[2014-06-19 17:20:26 - ARIN] C:\Users\NAME\Documents\NAME\NAME\ARIN\res\menu\navigation_screen.xml:5: error: Error: No resource found that matches the given name (at 'title' with value '#string/action_upload').
I even tried a Project clean in eclipse, but still problem persists.
Does anyone know how to fix it?
Thanks
This may seem like a weird answer, but did you save the xml file. Hit Ctrl-S and try it again.
If that doesn't work: Are the other strings you declared in the strings.xml file visible?

color-palette or third party plugin in order to set colors in eclipse

Is there easy way to manipulate colors in android ?
In dot.net we have color palette to change the color of
objects(button-background,text-color.. etc)
similarly is there any color palette/or/-any-plugins in object
browser of eclipse IDE at design time
Note:: I am aware of changing the color by adding color codes in styles.xml and referencing it in layout.xml
You can do this in some cases directly,
e.g in TextView you can change the Text Color by applying this statement in
Java code
textView1.setTextColor(Color.Red);
for other objects like buttons etc. you can not change their Color Directly like C#.
You have to create different .xml file and then you will store this .xml file inb drawable folder, in your activity_main(where button is created in your layout file) you have to make reference
e.g
<Button
android:background="#drawable/red_button" />
now the colored button .xml file located in
res/drawable/red_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/red_button_pressed" />
<item android:state_focused="true" android:drawable="#drawable/red_button_focus" />
<item android:drawable="#drawable/red_button_rest" />
</selector>
Check this Link for more Details

Change selection color on Button's and TextView's in Android

I'm developing an app and when I run it in the Emulator and I've selected a button (not clicked!) it shows an orange layer over it. When i click it i turns yellow.
On a HTC device the orange/yellow overlay is green. On a Samsung Galaxy S it's blue.
I want my app to have the same selection color's throughout the whole app (Blue to be precise).
Is this possible? If so, how?
I think link provided below could be helpful for you
link is: http://groups.google.com/group/android-developers/browse_thread/thread/a7ff938ce09e7c37
Yes it is possible. Use Themes to apply style to the whole app.
You r right
But u also set background color at runtime
& Another
possibility that may be HTC /Samsung has different Android Version ?
so this Happen
Create a selector in your drawable folder
for example drawable/item_selctor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/item_button_selected"
android:state_pressed="true" />
<item android:drawable="#drawable/item_button_selected"
android:state_focused="true" />
<item android:drawable="#drawable/item_button_selected"
android:state_selected="true" />
<item android:drawable="#drawable/item_button" />
</selector>
In your code or xml file use
item.setBackgroundResource(R.drawable.item_selector);
in code
or
android:background="#drawable/item_selector"
in xml layout file

Categories