Xamarin Forms Android splash screen landscape orientation - android

I am trying to implement splash screen in portrait and landscape. Following link https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
I added two separate files SplashBackground.xml and SplashBackgroundLandscape.xml with correct images. Added values-land folder with separate style.xml. Still the landscape image is not displayed on rotation. Am I missing anything?
Below is the style.xml for landscape. Portrait is same with drawable name #drawable/splash_portrait
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:windowBackground">#drawable/splash_landscape</item>
</style>
</resources>

Please see the updated screenshot with lower case names
Code for splash_landscape.xml. It has correct image name - splash_bg_landscape
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/colorPrimary" />
</item>
<item>
<bitmap android:src="#drawable/splash_bg_landscape" android:tileMode="disabled" android:gravity="center" />
</item>
Code for style.xml from values-land folder (for landscape mode)
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:windowBackground">#drawable/splash_landscape</item>
</style>
I feel everything is correct; however, when I deploy the app in landscape mode, it is not using the correct splash_bg_landscape image. App shows stretched portrait image. I am using Samsung device for testing.

I noticed that the item name "splash_landscape" is not same with "splashbackgroundlandscape",you may want to change that.
And below is my test sample solution structure you can take a look:
style(land):
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.companyname.myandroidtestapp">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:allowBackup="true" android:theme="#style/MyTheme" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:roundIcon="#mipmap/ic_launcher_round" android:supportsRtl="true" >
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

Related

Android activity theme goes behind navigation and status bar

In order to create a simple splash theme, I created a layer-list as 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/colorAccent"/>
<item>
<bitmap
android:src="#mipmap/test_mipmap"
android:gravity="top"
android:scaleType="center"/>
</item>
</layer-list>
And created a style using that:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
Then used this style as Application theme in AndroidManifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/SplashTheme"> ... </application>
When I ran the application, I noticed that the splash screen is somewhat full screen and status bar and navigation bar are being displayed in front of it. But once the main layout is loaded, it is displayed between navigation and status bars.
Here is the screenshot:
Above, it is clearly shown that the blue circle is behind the status bar!
If I create activity layout as following:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity"
android:background="#drawable/background_splash"> ... </android.support.constraint.ConstraintLayout>
and put the same drawable as the background of the layout, the circle is displayed at the right place! (From my point of view)
What I want is to make splash theme's size be the same as layout. Almost forgot to mention that I'm working with minSdkVersion version 16

How to make android layout background transparent?

How to make RecyclerView item background transparent I need to show background image?
I tried 3 solutions given in Stack Overflow and not worked for me
1 : android:background="?android:attr/selectableItemBackground"<br>
2 : android:background="#android:color/transparent"<br>
3 : alpfha 0.4
udated i also tried
4: android:background="#null" (Answer from this post) and not working
full xml code
Try to give this on your item CardView
app:cardBackgroundColor="#android:color/transparent"
Try this:
1) In your manifest make that activity theme to Transparent-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhub4you.transparent.background"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.androidhub4you.transparent.background.MainActivity"
android:theme="#android:style/Theme.transparent"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2) Now your page will be 100% transparent, so if you need some background color then set opacity like-
<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="#80000000"
tools:context=".MainActivity" >
it helps you.
So for the layout you are inflating for the item you can use
android:background="#null"
You can also use developer options on your device to see layout bounds or check the view hierarchy to see which item is giving you problems
First add this style in styles.xml
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<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:backgroundDimEnabled">true</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
</style>
then add this line in AndroidManifest.xml below the corresponding activity
android:theme="#style/Theme.Transparent"/>
hope it helps.
set all layout backgrouncolor= '#00000000' also to your Recycleview background color to achieve this view
set transparent color in your view
#80000000

Android windowBackground in theme not working - Splashscreen

I'm trying to add splash-screen to my Android app.
I've been following instructions from here. It's the standard way as I get it, and it seems logical.
So it's really simple right? Create drawable resource, use it in a theme as windowBackground, use the theme? Well it doesn't work for me...
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="euroicc.sicc">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme.Splashscreen">
<activity android:name="euroicc.sicc.ui.MainActivity"
android:theme="#style/AppTheme.Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
styles:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:spinnerDropDownItemStyle">#style/mySpinnerItemStyle</item>
<item name="android:itemBackground">#color/main_background</item>
<item name="android:textColor">#color/text_default</item>
<!--<item name="android:popupMenuStyle">#style/MyAlertDialog</item>-->
</style>
<style name="AppTheme.Splashscreen" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">#drawable/splashscreen_drawable</item>
</style>
</resources>
splashscreen_drawable:
<?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="#android:color/holo_green_light"></solid>
</shape>
</item>
<item>
<bitmap android:src="#drawable/splashschreen_eicc"
android:gravity="center"></bitmap>
</item>
</layer-list>
I've tried other codes from other sites, but nothing seems to work.
Only white background is displayed for less then a second (approximately), and then the app starts running. I'm setting the theme AppTheme in onCreate method of main activity so it uses it's default theme always except on start.
I'm also overriding onPause and onResume, but I call their supers, so that shouldn't be a problem.
I'm testing on v7.0.0, but that shouldn't be a problem also?
I have more styles but I removed them from the example code, because they are used for dialogs and elements inside xml files, not for activities.
So what is the problem and how do I solve it? When I first read about splashscreens I thought setting windowBackground would've been enough
You don't set your background in styles.xml, rather inside your splashcreen layout xml file. Here is my layout example:
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription"
android:background="#drawable/green" ==============================> HERE!
tools:context=".activity_splash_screen">
<ImageView
android:id="#+id/logo"
android:layout_width="#dimen/_150sdp"
android:layout_height="#dimen/_150sdp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/_100sdp"
android:src="#drawable/white_logo"
/>
<ImageView
android:id="#+id/title"
android:layout_width="#dimen/_240sdp"
android:layout_height="#dimen/_150sdp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/_100sdp"
android:src="#drawable/title"
/>
If you need help with the entire code, I can help you!
I've had this problem. I created the splash screen as a layer-list drawable, and in the theme as windowBackground as it is recommended everywhere, yet it wouldn't work on some devices (like my and my friend's Motorolas, a few other phones) - a black screen would be shown. For me the solution was to wrap my splash activity code in a Handler's postDelayed runnable with some small delay:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Handler(Looper.getMainLooper()).postDelayed( { //this is a trick so the splash screen - in window bg theme - is displayed on all devices, instead of black screen. E.g. moto g6
val startMainActivityIntent = ...
startActivity(startMainActivityIntent)
finish()
}, 100)
}
I am not particularly fond of delaying UI, if I knew a better way that worked, I would not do this. But it’s better than black screen.

Android - Actionbar

i want to change the color of the actionBar, i was reading the appcelerator docs and reproduce the code with no results.
What am i doing wrong ?
tiapp.xml
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="#style/Theme.CustomActionBar"/>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" android:maxSdkVersion="23"/>
</manifest>
<manifest android:versionCode="3" android:versionName="1.0.1"/>
</android>
custom theme
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.CustomActionBar" parent="#style/Theme.AppCompat">
<item name="colorPrimary">#1565C0</item>
<item name="colorPrimaryDark">#0D47A1</item>
<item name="colorAccent">#FF80AB</item>
<item name="colorControlNormal">#757575</item>
<item name="colorControlActivated">#FF6E40</item>
<item name="colorControlHighlight">#FF4081</item>
<item name="colorSwitchThumbNormal">#BDBDBD</item>
<item name="android:colorButtonNormal">#BDBDBD</item>
<item name="android:colorEdgeEffect">#FF4081</item>
</style>
</resources>
Screenshot
Thanks in advance..
Titanium Appcelerator 4.5
SDK: 5.2.0 GA
Genymotion
Remove this line: <manifest android:versionCode="3" android:versionName="1.0.1"/> and put the android:versionCode and android:versionName into the first manifest tag.

Frame by frame animation problems with Gingerbread 2.3.6

Objective:
Frame by frame animation on an ImageButton without the user having to "click" it, all through xml as well. This has already been accomplished, but it won´t work for Android 2.3.6, and I can´t for the life of me, figure out why.
Set up:
The project is clean, there´s nothing else but a main activity and an ImageButton within that main activity.
Main activity:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageButton
android:id="#+id/main_tree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:contentDescription="#string/main_tree"
android:background="#00000000"
android:soundEffectsEnabled="true"
android:padding="30dp"
android:src="#drawable/growing_tree" />
</RelativeLayout>
As you can see, the ImageButton points to the drawable growing_tree, an xml SELECTOR.
growing_tree
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/anim_growing_tree"
android:state_enabled="true" />
</selector>
And this one in turn points to the actual frame by frame animation.
anim_growing_tree
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/tree1" android:duration="150" />
<item android:drawable="#drawable/tree2" android:duration="150"/>
<item android:drawable="#drawable/tree3" android:duration="150"/>
<item android:drawable="#drawable/tree4" android:duration="150"/>
<item android:drawable="#drawable/tree5" android:duration="150"/>
<item android:drawable="#drawable/tree6" android:duration="150"/>
<item android:drawable="#drawable/tree7" android:duration="150"/>
<item android:drawable="#drawable/tree8" android:duration="150"/>
<item android:drawable="#drawable/tree9" android:duration="150" />
<item android:drawable="#drawable/tree10" android:duration="150" />
<item android:drawable="#drawable/tree11" android:duration="150" />
<item android:drawable="#drawable/tree12" android:duration="150" />
</animation-list>
It´s all quite straight forward. Just in case I´ll add the manifest file too.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.marstudio.memorytree"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.marstudio.memorytree.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I run it with an emulator of a Nexus-S with android 4.2.2 it works fine, as soon as the screen comes on the frame by frame animation begins.
Both .xml files are under res/drawable
Now when I run it on a real device with Gingerbread 2.3.6 the screen comes on but the it stays on the first frame, the animation won´t continue. What could I be doing wrong? I´d really appreciate some input!
I just had a similar-ish problem; I tested my application on 3 different live devices and here's my conclusions.
If I declared my animation drawable to be the background of an ImageView in an XML layout file, it'd work fine on Google Nexus 4 but on HTC One and Sony Xperia Z1 it would basically show the 1st frame and not animate at all.
Yes, the OS versions on all the phones are different (HTC One hasn't got 4.4 yet, for example) but since you've had a similar problem on 2 completely different versions of Android, this leads me to believe that there's some major differences in how the code behaves under different Android flavours - i.e. you have to start the animations "properly" for them to work on all phones.
Example code snippet:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
splashImageViewAnimatedBeep = (ImageView) findViewById(R.id.splashImageBeep);
splashImageViewAnimatedBeep.setBackgroundResource(R.drawable.splash_animation_beep);
splashAnimationImageViewBeep = (AnimationDrawable) splashImageViewAnimatedBeep.getBackground();
splashAnimationImageViewBeep.start();
}

Categories

Resources