Android: how to create splash screen with text - android

How can I add some text to splash screen? My splash screen isn't a separate activity and I don't want to make it as standard activity.
I created it by following this article:
https://android.jlelse.eu/launch-screen-in-android-the-right-way-aca7e8c31f52
Is it possible to add some text?

You can create a new layout for your splash screen. But if you still don't want to create it then there is a nasty hack to achieve it.
Open Paint write your text and save the file as png image
Import png file in drawables and add it in <layer-list> as an item below or above your logo/icon
<item android:bottom="50dp"> set position as you want
<?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/icon"/>
</item>
<item android:bottom="50dp">
<bitmap
android:gravity="center"
android:src="#drawable/myTextImage"/>
</item>
</layer-list>

Related

How can I place a word in the center of a splash screen in Android?

[Activity(Label = "Test", Theme = "#style/LaunchTheme", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
<style name="LaunchTheme" parent="Theme.AppCompat">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:navigationBarColor">#ffffff</item>
</style>
Here's my current splash screen in file splash_screen.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/black"/>
<item>
<bitmap android:src="#drawable/splash_logo"
android:tileMode="disabled"
android:gravity="center"
android:layout_gravity="center"/>
</item>
</layer-list>
What I would like to do is instead of the logo I would like to place the word "Test" so it appears in white text in the center, vertically and horizontally.
Could anyone give any suggestions as to how I can do this?
just you a text View and make its align center if you are use relative layout use
android:layout_centerInParent="true"
constraint layout use this
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
and if you are using linear layout use layout_gravity=center
Splash Screen only accepts Drawable resources, that is, if you want to put text into this screen, you'll also need to rasterize your text. After the is ready, you can put it under your project's Resources/Drawable folder, and use it in splash_screen.xml like:
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/black"/>
<item>
<bitmap android:src="#drawable/yourImageName"
android:tileMode="disabled"
android:gravity="center"
android:layout_gravity="center"/>
</item>
</layer-list>
Please use your favorite search engine with keyword as 'How to Add a Splash Screen—The Right Way' to find proper resources for your question.

Image in splash screen is repeated

I'm intending to show a very simple splash screen using a theme and an #drawable xml for the background.
Styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#color/white</item>
<item name="android:background">#drawable/splashx</item>
</style>
Splashx.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash"/>
</item>
</layer-list>
For some reason, the top few pixels are repeated when the splash screen is displayed, like so:
The actual image that I used obviously doesn't have this distortion on top (the little triangle on top which is essentially the hand and the club repeated from below). I've tried it with a few other images, too. Same mysteria.
Any ideas?
Why don't you try shifting your image from drawable to the mipmap folder? and then adding the mipmap image as a bitmap to your layer list.
<?xml version="1.0" encoding="utf-8"?>
<item
android:drawable="#color/your_background_color"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/your_image"/>
</item>
See the link here: https://www.bignerdranch.com/blog/splash-screens-the-right-way/

Android: How to create a customized edit text box like this?

I'm trying to create to make this form in Android
You see the EditText has some shadows at the front. How do I create that?
I created AutoComplete Text Views for State and Place. But how to I add that line and arrow on it?
You can set background drawable to achieve.either create custom drawable with shape or use background images and put it in the layout xml
android:background="#drawable/text_bg"
create an "testing_gradient.xml" file in /res/drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/grey">
<shape
android:shape="rectangle"
android:thickness="10dp"></shape>
</item>
<item
android:drawable="#color/white"
android:left="50dp">
<shape android:shape="rectangle"></shape>
</item>
</layer-list>
apply the code in layout xml file
<EditText
android:background="#drawable/testing_gradient"
android:layout_width="match_parent"
android:textColor="#color/black"
android:text="User input"
android:paddingLeft="60dp"
android:layout_height="60dp"/>
final result
Again, you can add more layer to input more images

How to deal with scaling and transparency of a bitmap as android:windowBackground

I am trying to set a global background image for my android application. The image is a PNG file with transparency. I set it in the following way:
<style name="MyAppTheme" parent="#style/Theme.AppCompat">
<item name="android:windowBackground">#drawable/background_main</item>
</style>
And drawable/background_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_main_bitmap"
android:gravity="bottom|center_horizontal" />
My PNG file should sit at the bottom of the screen always, being scaled to match the screen size always. With the above code, however, I am facing two problems.
The transparent background of the PNG file is black while I want it to be white.
The PNG file is larger than the screen width and hence, I can only see a portion of it. It is not scaled to match the width of the screen.
How can I accomplish these two things, possibly without havin to write Java code? (Although it would be better than nothing...)
Problem #1 can be solved with a layer-list in drawable/background_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
<item>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_main_bitmap"
android:gravity="bottom|center_horizontal|fill_horizontal" />
</item>
</layer-list>
Problem #2 remains though...
just change the property of android:gravity like following:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/flush"
android:gravity="fill_horizontal|fill_vertical"/>
Actually, using layer-list may give you expected scaling:
All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate. To avoid scaling items in the list, use a <bitmap> element inside the <item> element to specify the drawable and define the gravity to something that does not scale, such as "center"
Thus, the following drawable will suit your request:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/white" />
<item android:drawable="#drawable/background_main_bitmap" />
</layer-list>

How to overlay icons?

Those icons you can find in the sdk/platforms/data/res/drawable-hdpi... such as ic_delete. How would you go about overlaying one of those icons on a .png, using drawables?
you can place different shapes in one single layer list. In this example below, your custom drawable will be drawn on top of the android drawable ic_custom.png
example:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/layer_delete">
<bitmap android:src="#android:drawable/ic_delete" android:gravity="center" />
</item>
<item android:id="#+id/layer_custom">
<bitmap android:src="#drawable/ic_custom" android:gravity="center" />
</item>
</layer-list>

Categories

Resources