Show bg image with progress-bar on splash screen - android

I am trying to show a BG Image and Progress-bar on splash screen.
Code for splash.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent" android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:background="#drawable/spalsh">
<ProgressBar
android:id="#+id/loading"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:indeterminateDrawable="#layout/progressbartemplate"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="10dp" />
</FrameLayout>
Then on Style I have
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background" >#layout/splash</item>
</style>
Then I applied this style to Activity in manifiestfile
<activity
android:name="com.test.SplashActivity" android:theme="#style/SplashTheme"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But when the app starts I can not see the image and progress-bar while same i can see on the design view.
Same code will work if i use Layer-List and remove the progressbar.
Can someone pls suggest me how can i show the bg image with progress-bar at bottom?
Thanks in advance

I think there is problem in size of splash image you have to resize it by follow blow steps
1- right click on res
2- right click on drawable
3- click on new
4- Batch Drawable importer
5- click on plus + chose splash
I hope it will help you

try this, I hope this may resolve your issue.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/ic_launcher"
tools:context="com.example.viral.myapplication.MainActivity">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:padding="12dp"/>
</RelativeLayout>

Related

Options Item Selected change background color when state pressed

I want to change my background color, when my menu item state is "pressed" like this in the image below:
Exmaple
So how to achieve it?
My menu:
<?xml version="1.0" encoding="utf-8"?>
<item android:id="#+id/detail_edit_item"
android:title="#string/edit"
android:icon="#drawable/ic_edit_white"
app:showAsAction="always"/>
<item android:id="#+id/detail_delete_item"
android:title="#string/delete"
android:icon="#drawable/ic_delete_white"
app:showAsAction="always"/>
Here is a workaround which you can use:
For API level 11 or above you can use toolbar widget:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.myapplication.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titel"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/background_selector"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
To use this toolbar you have to set NoActionBarTheme for your activity
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have just used an ImageButton with my custom delete buttons in this example, after that you can write you selector to handle button press as follows:
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="#drawable/delete" android:state_selected="true"></item>
<item android:drawable="#drawable/delete" android:state_pressed="true"></item>
<item android:drawable="#drawable/delete_not_selected"></item>
You can save this code under drawable folder as background_selector.xml and this should work fine. you can find both images below but delete_not_selected is not visible because it is of white color but you will still be able to download it by clicking on the right side of the delete button.

Android Splash Screen Center Image

I have an app with a splash screen view that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<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="#android:color/black">
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/splash2"
android:scaleType="centerInside"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/txtVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:textSize="20dip"
android:visibility="invisible"
android:text="Version "/>
<LinearLayout
android:id="#+id/lvSplashInfo"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="invisible"
android:background="#android:color/black">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bleh"
android:layout_margin="5dp"
android:layout_gravity="center_horizontal"
android:textColor="#android:color/white"/>
<TextView
android:id="#+id/txtPercent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0% of the total"
android:layout_margin="5dp"
android:textSize="18sp"
android:gravity="center_horizontal"
android:textColor="#9DBA32"/>
<TextView
android:id="#+id/txtFilename"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="File name: xxxxx"
android:layout_margin="5dp"
android:textSize="18sp"
android:visibility="invisible"
android:gravity="center_horizontal"
android:textColor="#android:color/white"/>
</LinearLayout>
</RelativeLayout>
It renders an image scaled and centered into the screen. Unfortunately, this isn't working well for us. It causes a slight flash of white before it loads the view. My solution was to use an activity style. That works great, except I can't seem to center AND scale the image. I can center it easily, but it is wider than the screen. Here is my xml drawable:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/black"/>
<item>
<bitmap
android:gravity="center|bottom|clip_vertical"
android:src="#drawable/splash2"
/>
</item>
</layer-list>
How do I scale and center that splash2 image?
You can make the image in Photoshop, put it in the xml then center the whole thing, but I would recommend having a Splash screen while loading the app, because if you have it with a timer it wastes user's time...
So that's what I did to have a splash screen like this one:
First, you have to add a new Java class, let's call it SplashActivity.java
You don't have to add much to it:
package YOUR-PACKAGE-NAME;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}
After that, you have to have a drawable for the splash screen, because if you have a layout it will appear when the app is already loaded, so there won't be any sense in the Splash...
Go to the drawable folder and create a file named background_splash.xml.
There you add
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center">
<item>
<bitmap
android:src="#drawable/ic_splash"
/>
</item>
</layer-list>
where ic_splash is the image I created with Photoshop with resolution 1280x720 and then created a 9-patch image... (You have to have the 9-patch image, not to have normal, small and cropped image on different devices..) So go here and generate yours... Create it, download it and copy all the folders (mdpi, hdpi etc) to your res folder...
Now, go to your values/styles.xml and add the NoActionBar style
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
THEN open your Manifest.xml and edit the activity with intent-filter.
Yours should be
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
so replace the .MainActivity with .SplashActivity and the .MainActivity as another activity, so in the end you should have at least two activities declared at the Manifest.xml:
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher" or "#mipmap/ic_launcher"
android:theme="#style/AppTheme">
</activity>
Good luck! :)
If there are any troubles, ask :)

How to make the statusbar black (default) in android?

One of my activities has suddenly changed its color in the statusbar. By default it's black, but now it's transparent, why?
I've marked around the bar with a circle. By default this is black
My XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:id="#+id/do2get"
android:src="#drawable/loading"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="30dp" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminateTint="#00796b"
android:id="#+id/progressBar"
android:layout_below="#+id/do2get"
android:layout_centerHorizontal="true"
android:indeterminateTintMode="src_in"/>
</RelativeLayout>
I think its all about your actitiy`s theme.
First of all check this links:
How to change the status bar color in android
How to change the background color of android status bar
Maybe your base theme has attribute "android:windowTranslucentStatus" = true or "colorPrimaryDark = #android:color/transparent" etc. So you need to create new one style like:
<style name="YourActivityTheme" parent="BaseAppTheme">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:statusBarColor">#android:color/black</item>
</style>
and then set this style to current activity theme in AndroidManifest:
<aplication
....... >
.......
<activity
android:name=".chapters.home.YourNiceActivity"
android:theme="#style/YourActivityTheme">
<intent-filter>
...
</intent-filter>
</activity>
.....
</application>

How to make an image button that displays a different image when clicked? (android, eclipse)

I want to make an image button that when clicked it displays a different image on the same page without going to any other page and also being able to add a button when this photo is displayed to save the photo or to view it using the device default photo viewer, something like when you make a class and you type in the application settings
like that:
<activity
....
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
....
</intent-filter>
</activity>
So if you could help me that would be great, Thanks
Add a selector:
In your ImageButton's activity's layout xml:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mybutton"
android:src="#drawable/button_selector"/>
button_selector.xml in drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_clicked="true"
android:drawable="#drawable/button_clicked" /> <!-- clicked -->
<item android:drawable="#drawable/button_default" /> <!-- default -->
</selector>

How to remove the white border around the image in splash screen in full screen

I am currently working on a splash screen with an image view. The problem is that when the splash screen is shown, there is a white border around the image. So that the splash screen shows the image with the white border around. I would like to remove the white border completely. Is there any one who know the reason for this or any suggestion?
Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView android:id="#+id/ImageViewSplash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:contentDescription="#string/splashImageContentDescription" />
</RelativeLayout>
I apply a transparent background in the theme/style I use for my splash pages, this way I don't have to distort the image being displayed to fit the screen size of the device. This works particularly well when using PNG files that contain a transparent background.
Here's the style I use for this "Transparent" theme:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
You then apply this theme to the splash activity in your application manifest as follows:
<activity
android:name="com.masseria.homework9.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It seems to me like you could remove everything from your layout except for the ImageView. So it would look like this:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ImageViewSplash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:contentDescription="#string/splashImageContentDescription" />
Then you could play around with the scaleType on the image until you found one that filled the screen. If none of that works, I would suggest increasing the resolution of your image file.

Categories

Resources