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.
Related
I have a basic MAUI project and I want to set an SVG file as the splash screen.
I have tried to modify the csproj file using the code below:
As you can see the photo is cropped in a circle
How can I make the splash screen display the entire photo?
You cannot (at least not without going a long way using a separate splash screen activity).
That's a limitation of Android: https://developer.android.com/develop/ui/views/launch/splash-screen
The picture also needs to fit into the frame and should be squared. You can set the base size for that in the <MauiSplashSceen> build action in your .csproj file.
You may also be interested in this: Custom NET MAUI Splash screen
There currently also is a bug in MAUI's resizetizer which requires giving the SVG file an entirely new name each time you want to change it: https://stackoverflow.com/a/74336491/4308455
I've written a blog post about the Splash Screen in MAUI, which might also be of interest: https://ewerspej.hashnode.dev/lets-customize-the-splash-screen-of-a-maui-app
For the device which android version is lower than 12.0, you can use the following code to make the image full full the splash screen.
Delete the old splash image in the Resources/Splash folder.
Put your image in it and set it's build action as MauiSplashScreen
Create a xml file in the Platforms\Android\Resources\drawable\maui_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item>
<bitmap
android:src="#drawable/splash" //the splash is your image's name
android:dither="true"
android:gravity="fill"/>
</item>
</layer-list>
And then, your image will show in the full splash screen.
For the device which android version is lower than(or =) 12.0, the android system changed the api about the splash screen. The resource code about is the FrameLayout contains a ImageView and we can't set the ImageView layout_width and layout_height. For more information, you can check the answer in this link.
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.
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.
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
I need to set background of repeat image.
So i have a file repeat_dark_bg.xml in my drawable folder
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/repeat_dark_marked"
android:tileMode="repeat"
>
</bitmap>
repeat_dark_marked - image, which i want to repeat.
so then i use repeat_dark_bg.xml as background value of my linearlayout.
but whats a problem.. when i test my app on device sometimes image repeat_dark_marked repeat, sometimes it scales and resizes to full screen.. i cant understand why sometimes it shows this or that.. any ideas?
repeat_dark_marked.png is 9-patch ? make sure you dont have multiple repeat_dark_marked.png or repeat_dark_marked.9.png etc in your drawable folders. Check all drawable-mdpi, drawable-hdpi, drawable-ldpi folders.