xamarin.forms has a tutorial for creating splash screens in android
This code is my result from following the tutorial and it works
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/splash_background"/>
</item>
<item>
<bitmap
android:src="#drawable/monstersplash"
android:tileMode="disabled"
android:gravity="fill_vertical|fill_horizontal"/>
</item>
</layer-list>
But now I also want my image to aspect-fit on the page.
I found a number of posts suggesting the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/splashlinearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/monstersplash"
android:adjustViewBounds="true"
android:scaleType="fitCenter" ></ImageView>
</LinearLayout>
But this code results in a ResourcesNotFoundException: android.content.res.Resources$NotFoundException: Drawable com.companyname.BB.App:drawable/splash_screen with resource ID #0x7f070141
I tried different configurations with layer-list /linear layout but somehow the Imageview does not seem to be able to load my monstersplash.png image while the source parameter is the same as with the bitmap.
Any idea's?
Full context:
The above mentioned code lives in drawable/splash_screen.xml
in my styles.xml I have a reference to the drawable like so:
<style name="SplashTheme" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
And I created a splashactivity which references the theme
[Activity(Theme = "#style/SplashTheme", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
Since it works within Bitmap. The issue maybe caused by the IDE or project cache.
Delete the folder bin and obj in your project ,then clean and
rebuild it.
Delete all content in the file Resource.design.cs , then rebuild the project .
If it still doesn't work , you could create a new project and check if the issue still exists .
Related
So, I've almost finished my Android app using Flutter, and now I've just created the icons using Android studio tools (right click on "res" folder -> new -> image asset...).
So far so good, but now I'm having an hard time trying to figure out how to put the app icon in the loading screen.
What I did so far is:
Creating a styles.xml under res/values:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
</resources>
Creating a launch_background.xml in res/drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
<item android:drawable="#android:color/holo_green_light" />
<item>
<bitmap android:src="#mipmap/ic_launcher" />
</item>
</layer-list>
but the asset #mipmap/ic_launcher is not resolved... I have no idea how to specify it correctly!
In AndroidManifest.xml I've defined the theme as android:theme="#style/LaunchTheme" and the icon as android:icon="#mipmap/ic_launcher"... and since the icon is correctly used by the app once installed, I don't get why in the manisfest is resolved and in the other file is not... what I'm supposed to do?
I like the simplicity of Eric's response, additionally, there is thorough documentation on the flutter.dev website on how to do this without the additional package.
https://flutter.dev/docs/development/ui/splash-screen/android-splash-screen
So, after several attempts I've solved in by using the following configurations:
styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<color name="white">#FFFFFF</color>
</resources>
launch_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
<item android:drawable="#color/white" />
<item
android:width="400px"
android:height="400px"
android:drawable="#mipmap/ic_launcher"
android:gravity="center" />
</layer-list>
The relevant difference is that I'm now using a drawable for the logo instead of a bitmap. Currently, it works perfectly in release mode (flutter clean && flutter run --release), even though in debug mode a black screen is visible for few milliseconds before the main Flutter widget is actually rendered.
You can use a dev dependencies package: https://pub.dev/packages/flutter_native_splash
Add on pubspec.yaml
dev_dependencies:
flutter_native_splash: ^0.1.9
declare your icon launcher and color
flutter_native_splash:
image: 'assets/ic_launcher.png'
color: "#36133d"
and them run:
flutter pub get
flutter pub run flutter_native_splash:create
I want to change the color of my actionbar but I'm no good at making image resources so I want to know if there is anyway it is possible to do that without images. like setting a color to some property or something? I surfed a lot but there are too many confusing answers and I can't figure out which one to use.
I am developing for sdk above 8 so I'm using support libraries. Please help.
Generate what ever theme you want from Android Action Bar Style Generator
Copy all the files it generates to the respective folders in res folder and VOILA.. ;)
You could have easily found out the answer here. Or you can click here to create image resources very easily. But anyway, this is how you do it.
first of all, define a color you want for your actionbar in "colors.xml" in the "values" folder of your project like this:
<color name="customColor">#f1f1f1</color>
Then create a new .xml file in your drawable folder with the name say "actionbar_drawable.xml". It has to be a "shape" drawable.
drawable\actionbar_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#color/customColor"/>
</shape>
Now create "themes.xml" in "values" folder with the following code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="CustomActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:targetApi="11">#style/CustomBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/CustomBar</item>
</style>
<style name="CustomBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_drawable</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_drawable</item>
</style>
</resources>
Then in your manifest file, set the theme for your activity like this:
android:theme="#style/CustomActionBar"
That's all. Now you won't have to make any image resource. Hope it's helpful to you.
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(activity.getResources().getColor(R.color.my_color)));
I would like to change the expanded and default icon of my Expandable List View.
I did some research how to do this and found this question.
I think I did it just as it is described there.
I have 2 icons, the first is called defaulticon.png and the second one expandedicon.png. Bother are located in the drawable folder (not in drawable-hdpi).
My list view declaration looks like this:
<ExpandableListView
android:id="#+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:groupIndicator="#drawable/groupindicator">
</ExpandableListView>
The groupindicator is an xml file also located in the drawable folder and looks like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/defaulticon" android:state_empty="true"/>
<item android:drawable="#drawable/expandedicon" android:state_expanded="true"/>
</selector>
However the icons do not change. The default icon from the list view disappears and instead there is no icon.
Are there any restrictions with the resources (how big the resources can me (both are 160x160), where they have to be located,...).
I am testing the app on my S3 running Android 4.1.2.
Cheers
Change your icon size to 32 X 32, put your icon in drawable-mdpi and then try this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/expandedicon" android:state_expanded="true"/>
<item android:drawable="#drawable/defaulticon"/>
</selector>
First of all, resize your image to 24*24 and then copy it to the drawable-mdpi folder in Android. After that, copy and paste this code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/abc"android:state_empty="true"></item>
<item android:drawable="#drawable/downarrow" ></item>
</selector>
I'm developing an android project, and I want to use a <selector> in an XML file. I've put the <selector> in a file under res/drawable/default_item_background_selector.xml, and I'm referencing it with XML attributes like
<TextView
android:background="#drawable/default_item_background_selector"/>
The XML attribute content I get from Eclipse's content assist, so that can see it just fine. However, when I compile everything (and it compiles just fine) and debug it on either simulator or on a device, the app crashes, with a root exception of :
09-24 23:55:14.771: E/AndroidRuntime(22478): Caused by:
android.content.res.Resources$NotFoundException: File
res/drawable/default_item_background_selector.xml from drawable
resource ID #0x7f020000
The R.drawable.default_item_background_selector gets generated just fine, but at runtime, it appears there's no physical file generated in the output directory. Has anybody experienced this before ? Yes, I've cleaned and recompiled (so many times).
Created default_bg.xml in Drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true"
android:drawable="#drawable/red" />
<item android:state_pressed="true" android:state_selected="false"
android:drawable="#drawable/blue" />
<item android:state_selected="false"
android:drawable="#drawable/yellow" />
</selector>
Create drawables in **strings.xml** is
<drawable name="blue">#0000FF</drawable>
<drawable name="red">#FF0000</drawable>
<drawable name="yellow">#FFFF55</drawable>
And set background to textview
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:background="#drawable/default_bg"
/>
I use an ActionBarSherlock library in my app. I also needed to customize the ActionBar, so I added a custom theme with a background parameter set, like this:
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/action_bar_bg</item>
<item name="android:background">#drawable/action_bar_bg</item>
</style>
action_bar_bg drawable is simply a bitmap of tiled squares:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="#drawable/bg_img_actionbar"
android:tileMode="repeat" />
What I want to do next is to set a linear gradient for a whole ActionBar, so it will cover this background. And I have no idea if it's possible and how to do that.
Any help would be appreciated.
There is a type of resource for this, Shape Drawable:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape