I can see Delphi XE7 comes with splash/startup image support for Android.
However, when I choose to center the image (which looks best) Delphi shows black color around it. I would prefer white since it fits better with the image and color theme of the app. There does no appear to be an opion for background color where you set splash/startup images.
How can I change this color?
If you want fill the black background with the same background color from your image you must use 9patch images. To make 9patch pngs use NinePatch (included in android sdk)
Once you hace the images, add to your project and set up like this:
splash tile mode: disabled
splash gravity: center
Then go to project -> deployment:
Uncheck splash_image_def.xml (to not deploy)
rename your splash_image.png to splash_image_def.9.png
If you are just wanting to change the background color of the splash screen, you can modify two files. colors.xml and splash_image_def.xml. You will find these in the Android/Debug/ (or Android64/Debug/) folder of your project. These get recreated each time you deploy your application so you will need to make backup copies of them.
In Project|Deployment, untick these items and create new entries for the copies you have made, making sure that you deploy them to the same location. You will end up with two entries for Debug and Release.
Edit colors.xml and add the new color that you want like so
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="notification_accent_color">#000000</color>
<color name="logoblue">#0094ff</color>
</resources>
Here I've added the logoblue color. Next edit splash_image_def.xml and change #android:color/black to #color/logoblue. It should look somewhat like the following
<?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/logoblue" />
<item>
<bitmap
android:src="#drawable/splash_image"
android:antialias="true"
android:dither="true"
android:filter="true"
android:gravity="center"
android:tileMode="disabled"/>
</item>
</layer-list>
There might be a simpler way of doing this, but this is what I've come up with through a bit of trial and error.
There is no background color property of splash images because this is supposed to be a part of the image. There are 4 different possible sizes for Splash Images on Android:
426 x 320
470 x 320
640 x 480
960 x 720
So, depending on your supported devices, you should have up to 4 images matching these sizes, with the background color being whatever you wish. Set it up to fill the entire screen, and make sure you're not using transparency. For Splash Gravity, select the fill option.
to change default black splashscreen, just open
splash_image_def.xml at debug folder,
and change "black" to white if you want change it to white, like this
<item android:drawable="#android:color/white" />
Note : Build it with no change at source code, layout or anything at RAD Studios. Just edit the file xml with notepad, save it, then rebuild.
Related
My app's launcher icon is vector-drawn (as opposed to image-drawn). It is launched with
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#color/appColorDark" />
<foreground android:drawable="#drawable/ic_myIcon" />
</adaptive-icon>
However, the icon is severely cropped (i.e. only partially visible) in the preview display (and therefore in the ultimate launcher icon).
QUESTION: is there any attribute in XML (or alternatively, in code) I can use to scale the icon down, so that it fits nicely (i.e. with the required padding) in the previewed colored background? That code would also come in handy whenever I want to use the same vector file somewhere else in the app.
My solution now is to go back to Inkscape, reset the borders, resave the file in Android Studio, have a look in the preview, back to Inkscape etc. till it fits. Not ideal.
I suggest you to create a launcher icon in the form of a mipmap where the launcher will adjust to the device on which the application will be installed.
of course you can easily create the mipmap file here : https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html
you can make some adjustments here. of course this way is easier and better I think. you just need to overwrite the existing mipmap file with the new mipmap file.
I hope this helps
You can wrap the pathData in your ic_myIcon.xml drawable with group tag and then play the scale.
<!--Reduce scaleX and scaleY until desired size is achieved (note: 1 = 100%).
You may also need to adjust the position (translateX and translateY) after scale adjs.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
...
>
<group
android:scaleX="1"
android:scaleY="1"
android:translateX="0"
android:translateY="0"
>
<path
android:pathData=.../>
</group>
</vector>
You can create the launcher icon using Image asset studio which is a preferred way and recommended by android dev team.
image asset studio
I got this strange problem with a 9-patch in Android, which i want to use as a splash-screen. I use a build-in Android Studio plugin to create a 9-patch, but it doesnt't work properly with images with too high resolution.
This is a simplified version of what I do in generator (X is the symbol of black pixels):
X X
************X
X ************X
************X
****LOGO****X
************X
X ************X
************
XXXXXXXXXX
When i try to use it as a activity background it behaves like a normal bitmap, not like a 9-patch - it is displayed in original resolution and doesn't fit the screen. This is the code of XML file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorPrimary"/>
<item>
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/patch_logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
I decided to test it as a background of a layout, in that case it was the FrameLayout where I load fragments with initial settings. This image shows two previews - on the left is used a normal png, 800x800. On the right side is a 9-patch file of the same image.
previews
As you can see, left image is just stretched to fit the layout. Right image, although in preview it looks like when i was using xml drawable as a background of activity, on a real device it is displayed exactly like using normal png - it is just stretched.
When I use 500x500 image 9-patch it is a little bit too big on preview, but on my device it looks good, just the resolution is too low.
All 9-patch files are stored in drawable folder, it is not specified for any density.
This is the logo I want to use logo
I was trying to find the solution all day. What am I doing wrong?
My problem is that the App Icon on my device looks way too small in comparison to the other apps. I read some solution on other questions, like this one Android App Icon size too small but this doesn't seems to be my problem. In the Android Studio you can make a right click on "res" where you can find new --> image asset where you can create such a icon. it creates icons for all the different sizes like mdpi, hdpi and so on. So i thougt that i might display the app icon correctly but it doesn't. can anybody help me?
In "Configure Image Asset", click "Legacy", change "Shape" from "Square" to "None", and the image padding will appear. Go back to "Foreground Layer" and resize the image to fill the padding.
Try to use this. Its very useful, fast and free. And thats what I use.
If your icon already has a shape, remember to set the shape to none. Hope it helps!
If you are getting the same results, I also recommend this website, where I usually get "bigger" icons.
I found the launcher icons generator puts there a small padding, that is the reason for smaller icons. On the other way it is recommended by Google team here.
Android expects product icons to be provided at 48dp, with edges at 1dp.
All is on you to decide. In case the icon applies to whole square space - use padding, otherwise when small object is not square shape, rather fit to edges :)
I had the same issue. I fixed it like so:
Create the adaptive icon through Android Asset Studio. In the third tab you can select "Create Legacy Icon". Only this legacy one is going to be too small! The others will be fine.
So the thing I did was just to replace the icon_launcher.png files (this is the legacy icon).
If you use any single image directly as android:icon="#drawable/ic_launcher"
It'll be shown correctly on old devices but on android 26+ it'll appear small
Use this approach to make the icon appear like fitXY scaleType for imageview, that is, it's corners can be clipped like cardview but it will not be shrinked
Step 1
Delete ic_launcher from drawables and paste it in mipmap-xxhdpi-v4
Add transparent padding of width/6 px to your launcher icon online
Step 2
Paste the second file as ic_launcher_foreground
Step 3
Create ic_launcher.xml under res/mipmap-anydpi-v26 and add this content
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<foreground android:drawable="#mipmap/ic_launcher_foreground" />
<background android:drawable="#color/colorTransparent"/>
</adaptive-icon>
Step 4
Edit the manifest and use mipmap instead of drawable
Now your icon should not appear shrinked/zoomed
This is useful when your app icon can't be split into foreground/background eg some graphic image as app icon
How it works:
For API26+ devices, mipmap-anydpi-v26 will take precedence over mipmap-xxhdpi-v4 and system will load icon from xml, which in turn, loads foreground from ic_launcher_foreground, automatically crop 2/3 of its size because it's 'adaptive icon'. (This is the reason we add padding of width/6 from all sides
For older devices the ic_launcher.webp will be used directly
Tested on API 21-31
I am still kinda confused on how to re size images to fit on a small,normal and large screen on an android phone.
Say I have a image that is 500px by 500px and is a JPG.
I want to make 4 image buttons making it a 2 by 2 in the center of the screen. For simplicity sake assume I am using this same image for all 4 buttons.
Now how do I figure out how much I need to re size the image down for each of the screens?
So that it would look like this in the center of the view.
x x
x x
Have you looked at Supporting Multiple Screens in the Android Dev Guide?
I think you want a 9-patch drawable (*.9.png). They allow you to make stretchable graphics and declare a content fill region. Android's stock buttons use them.
http://developer.android.com/guide/developing/tools/draw9patch.html
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
For buttons you'll probably want to make them change based on what state they are in. You use StateList drawables for that.
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
Here's an example of a button StateList from one of my apps to render an Action Bar button.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/slight_white" /> <!-- pressed -->
<item android:state_focused="true" android:drawable="#android:color/transparent" /> <!-- focused -->
<item android:drawable="#android:color/transparent" /> <!--menu_normal default -->
</selector>
In this case I'm using colors but you can of course replace that with any drawable as well. Including the 9-patches drawables you make.
For a full fledged example look at the source code that comes with the SDK.
%ANDROID_SDK_ROOT%\platforms\android-12\data\res\drawable\btn_default.xml
I am trying to set a 9-patch image as the background for one of my activities but it is stretching unescessarily making everything get all wierd. I used draw9patch to create it and added one pixel to the bottom left and one pixel to the top right. I then save it into my drawables directory as intro_bg.9.png. I want to stretch the very bottom and stretch the far right side but only if it has too. If it doesn't then I would like it to stay in tact.
When I set it as the background of the parent layout however it stretches it both horizontally and vertically and it doesn't even show my buttons when I run it on my droid.
I've done the Google searches but there is no good info on how to get something like this working. What am I missing?
I have also tried some other configurations including using the padding sides(right and bottom) but that gave the same results.
Thanks
Code to set as background:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/intro_bg"
>
Looks like:
Should look like:
Your image is just too big to fit the layout. If you want it to be contracted you need to paint a line on the top and left borders -- the line marks region which will be contracted or stretched. I guess right now you have just dots on the borders.
Second option is to set the image as activity background, then it will be fitted in the screen. To do this add styles.xml to res/values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ExampleTheme" parent="android:Theme">
<item name="android:windowBackground">#drawable/intro_bg</item>
</style>
</resources>
Then apply the theme to your activity at the manifest. The intro_bg drawable even doesn't need to be a 9-patch.