Android: Vector drawable is not repeating - android

I am using below code. "#drawable/ic_keyboard_arrow_down_black_24dp" is vector image and below you can see xml for bitmap and also you can see Error in screen shot thanks .
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_keyboard_arrow_down_black_24dp"
android:tileMode="repeat"/>

to use vector image you have to set the attribute with srcCompat as:
xmlns:app="http://schemas.android.com/apk/res-auto"
app:srcCompat="#drawable/ic_keyboard_arrow_down_black_24dp"
But since src is the required attribute of the bitmap and you can not set vector image to src. Thus you have to use .png or any other image type.

Did you try running/building the app. Often you can have the automatic xml renderer fail however the app will still build fine.

Related

How to change size image of splash by using migrate?

I I try to make splash screen by using migrate. But I do not change resize image that I used. Here is my picture.
What I do:
implementation 'androidx.core:core-splashscreen:1.0.0-beta02'
I added this implementation to gradle.
I made theme part like
this
I put this theme in manifest.
Finally, I added this in main activity
I hope, someone can solve this problem.
I used a layer-list to resize my app logo:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="288dp"
android:height="288dp"
android:drawable="#color/splash_screen_background" />
<item
android:drawable="#drawable/app_logo"
android:gravity="center" />
</layer-list>
The library specs can be found here
That image seems too small and possibly should be round with transparent background. In the alpha version, the scaling still worked differently and when upgrading from there, the image didn't fit anymore. Would need to look it up, because one can find the perfectly correct (as expected by the library) dimensions of the splash screen image in the library resources. My code looks like this:
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
SplashScreen.installSplashScreen(this);
}
One would commonly use Photoshop or GIMP to change the size of the image (it's predefined). Using a vector drawable XML (similar to SVG) instead of PNG or WEBP scales nicely. And please don't post screenshots of code or errors; to show visual problems that's fine.

Pattern image setting in android studio show black tile in between?

This is screenshot when i was trying to set gradient in android studio
here is my code for set backgourd image as pattern -
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#mipmap/ic_bg_pattern"
android:tileMode="mirror" />
and i applied this XML file into the activity_main.xml file
android:background="#layout/backrepeat"
Note:- the image i was added from image asset.(but when i copy and directly paste it was working fine)
In My Case this works
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/single_img"
android:tileModeX="repeat"
android:tileModeY="repeat"
/>
#Abhishek answer is also correct but this is problem occurs when we try to use a patter image with some low pixels means 50x50Px so the image is not android draw the small image as tile format so we see clearly the black space if we use some big image like above 150*150px then it create the good texture that you want to use.

Image doesn't show up as my background in Android

I've added this attribute to my XML.
android:background="#drawable/background"
"#drawable/background" refers to the file background.psd which is located in the drawable folder.
The background does not appear when i run it (in the emulator).
What am i missing?
You can't use psd files as drawables. Try saving it as png.

Border line appear in drawable in Android

Hello I am trying to get Nine patch drawable from this tool Android Asset Studio, it generated the drawables of different density and that drawable I am setting as background of the button but drawables it generated has border line around images in four side that appear also when I am trying to run application in device.
Why it is so and can you please tell how this can avoided ?
<Button
android:id="#+id/submitButton"
android:layout_width="match_parent"
android:contentDescription="#null"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sign_up_views_vertical_top_margin"
android:background="#drawable/sign_up_via_email_selector" />
sign_up_via_email_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/sign_up_submit" />
</selector>
Thanks in advance
Check to see if the image has the correct name.
It should be sign_up_submit.9.png, the lines that appear are actually the areas that the 9patch defines for stretch.
If the image has the correct name it is a chance that the online utility application you used messed the resource. Try to use the 9patch generator from the android sdk(look for [your_sdk_path]\tools\draw9patch.bat), and try to generate one yourself and see if the problem is still there.
can you please check how you placed your 9 patch image in drawable folder,9 patch image should be named sign_up_submit.9.png

Image does not show completely white despite it's correctly white

For a splashscreen I use an image which contains a white background (pure white - checked in Photoshop). For some reason it shows a slight green bg vs. the activity's default white bg - as marked in the screenshot. Only in some devices, like the
I add this as single view in a frame layout to the activity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="#drawable/splashscreen" />
</FrameLayout>
Any idea? I read about RGB888 vs. RGB565 issues, but couldn't find a proper solution.
Note: I sure could make change the white in the image to transparent, but would prefer to understand the problem and find a proper solution.
This is really annoying. I wonder, why so few people encountered this problem as it should appear on all 32-bit displays.
You mentioned right about RGB888 format. The cause of the problem is that regardless of the original bitmap format in the APK files all bitmaps are compressed (in my case into indexed 256-color! wtf?).
I couldn't find the way to prevent it, so if anyone knows the proper solution, please tell.
However, I found two solutions for the white color problem.
1) Per-bitmap: Say, we have a drawable bitmap resource called #drawable/mypng, which causes the problem. We need to add an additional XML drawable drawable/mypng_nofilter.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/mypng"
android:filter="false"
/>
and use #drawable/mypng_nofilter instead.
2) For entire activity: In activity onCreate method we need to add
getWindow().setFormat(PixelFormat.RGB_565);
Now the window has 16-bit color depth and all bitmaps appear "properly" white.
Again, I would prefer to have 32-bit color depth, but I don't know how to control compile-time image compression.
I have solved this issue by changing the Bitmap.CompressFormat type to PNG instead of JPEG:
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.nouv);
Bitmap bitmap = (Bitmap)((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
I encountered the same problem with network loaded images. I solved the issue by disabling bitmap filter. Since I do not have the issue on ICS and newer devices, I turned off the bitmap filter only for pre-ICS devices. Following is the code I used (setting network loaded bitmap to the ImageView.)
BitmapDrawable bitmapDrawable = new BitmapDrawable(imageView.getContext().getResources(), bitmap);
bitmapDrawable.setFilterBitmap(false);
imageView.setImageDrawable(bitmapDrawable);
After using all the solutions in the Stackoverflow.
From changing android:src to app:srcCompact and many other solutions.
The thing which helped me was my image was inside drawable-anydpi and I moved the image from drawable-anydpi to drawable and it worked for me after 2 hours of research.
P.S: It might help someone too that's why I put it over here. :)
As your image only have a picture in its middle, I would advise you to set:
android:scaleType="centerCrop"
It will crop some part of your picture, at left and right, but will use the whole screen...
You can also define a background to your FrameLayout or your ImageView using the color of your picture (which seems to be F8FCF8):
android:background="#F8FCF8"

Categories

Resources