firemonkey android fullscreen with statusbar - delphi

how can i design my ui like the provided image
this is full screen and have status bar.
when i put full screen as true it hide the status bar
i also put status bar visibility as visibale or VisibleAndOverlap and select a color but it dont look like my sent image !!
is this kind of desgn available in firemonkey !?

you can do this by updating the default style. you must update the AndroidManifest.template.xml by somethink like
<application android:persistent="%persistent%"
android:restoreAnyVersion="%restoreAnyVersion%"
android:label="%label%"
android:debuggable="%debuggable%"
android:largeHeap="%largeHeap%"
android:icon="%icon%"
android:theme="#style/myAppTheme"
android:hardwareAccelerated="%hardwareAccelerated%">
and then you must provide a style.xml with the setting you need (like make the statusbar translucent)
exemple of style.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myAppTheme" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:colorPrimary">#ff2b2e38</item>
<item name="android:colorAccent">#ff0288d1</item>
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:statusBarColor">#ff0087b4</item>
</style>
</resources>
see exemple of a demo app that override the default style at https://github.com/Zeus64/alcinoe (demo is alfmxcontrols)

You can set the status bar and navigation bar background transparent with my code in github:
https://github.com/viniciusfbb/fmx_tutorials/tree/master/delphi_system_bars/
In this case you need to use:
uses
iPub.FMX.SystemBars;
...
Form1.SystemBars.StatusBarBackgroundColor := TAlphaColors.Null;
Form1.SystemBars.NavigationBarBackgroundColor := TAlphaColors.Null;
Form1.SystemBars.Visibility := TipFormSystemBars.TVisibilityMode.VisibleAndOverlap;

Related

Dark and Light mode in xamarin android programatically

Anyone have an idea how to change the theme Dark and Light mode in xamarin android programmatically.
First, the Dark theme is available in Android 10 (API level 29) and higher. https://developer.android.com/guide/topics/ui/look-and-feel/darktheme#force_dark
If you want to change the theme programatically, Apps must opt-in to Force Dark by setting android:forceDarkAllowed="true" in the activity's theme.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- 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:forceDarkAllowed">true</item>
</style>
</resources>
And then, to switch the theme, call the code below to force dark in OnCreate().
((AppCompatActivity)this).Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightYes);
Call the code below to disable.
((AppCompatActivity)this).Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightNo);

Xamarin.Android - Can you set your custom theme in the Visual Studio 2019 Android UI designer?

I'm playing around with styles and themes in my hello world android app:
For this I have a custom style as follows in my styles.xml file:
<style name="Theme.AppTheme.Custom" parent="#style/Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColor">#color/colorText</item>
<item name="android:colorBackground">#color/colorBackground</item>
</style>
My UI designer still looks different from my custom style, I have the option to change themes, but my custom theme is not in the list:
Is there a way to add custom themes to the UI designer...or even better to just let it display the same way it will eventually look in the endproduct?
The Theme drop-down menu displays all of the themes defined in the project
So it will add your custom theme to the theme list,but you need close the Visual Studio and restart it,then you could see your custom theme inside the theme list.
And you also could creat the custom theme by using Theme Editor

Xamarin forms: How to set background color for xamarin forms android splash screen?

Following is the splash screen code of my xamarin forms android:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:gravity="fill_horizontal|fill_vertical"
android:src="#drawable/splashbg"/>
</item>
<item>
<bitmap
android:src="#drawable/icon"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
I wanna remove the first bitmap(named splashbg) and provide a background color for the entire page. How to give background color in xamarin android? Currently showing black color.
Go through this, but not solving my issue.
Try adding android:color="#00aff0" for layer list, but not working...
Inside my splash activity theme i have set:
<item name="android:windowBackground">#drawable/background_splash</item>
then in drawable folder i have background_splash.axml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorSplash"/>
<item>
<bitmap
android:gravity="center"
android:tileMode="disabled"
android:src="#drawable/logosplash"/>
</item>
</layer-list>
and the color is in the values folder, colors.xml:
<color name="colorSplash">#2674B5</color>

How to change Entry cursor color in Xamarin.android

In my application need to change xamarin.android entry default color. In my application background image is black and default color of entry in xamarin.android also same color, so need to set different color. Please suggest any idea on that. I am trying fallowing code but I am not getting exact result.
In my xamarin.android project folder contain resource folder inside values folder, we have file 'styles.xml' file. In that is item name 'colorAccent' inside style tag like this.
Sample code:
<style name="MainTheme.Base" parent="Theme.AppComa.Light.DarkActionBar">
<item name="colorAccent">#ffffff</item>
</style>
In colorAccent item name default set as black, now I am change in to white but when run project like this all entry cursor color change to white but with cursor, entry's color also change to white. My requirement is only changing the entry cursor color, remaining is same.
If you're specifying theme for an activity, you can also define custom theme and set android:textCursorDrawable to #null. In that case cursor color will be the same as text color.
Here's an example from my working values/Styles.xml, note the last item tag:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="Project.Main" parent="android:Theme.Holo.Light">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:textCursorDrawable">#null</item>
</style>
</resources>
EDITED
If you want different cursor color to text color then you need to create EntryRenderer. and put following line in OnElementChanged of your Renderer class
IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView));
IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID (IntPtrtextViewClass, "mCursorDrawableRes", "I");
JNIEnv.SetField (Control.Handle, mCursorDrawableResProperty, 0); // replace 0 with a Resource.Drawable.my_cursor
you can style your cursor by adding XML file in "Resources\drawable" folder in Android project.
example:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<size android:width="1dp" />
<stroke android:color="#FFFFFFFF"/>
</shape>
and refer the file in your style.xml in "Resources\values" folder in Android project.
example:
<style name="MyTheme" parent="MyTheme.Base">
<item name="android:textCursorDrawable">#drawable/xml_file_name</item>
</style>

Switch in Xamarin.Android not rendering its UI

I have a Xamarin.Android project that has been in development for awhile. I went to use my first Android Switch control yesterday. When the UI rendered on my device (I don't use Xamarion.Android preview editor cause it continually crashes VS). It only showed off/on text, and no UI for the switch control at all. This seemed to happen regardless of what width/height I specified for the control etc.
I created a new Android project, dropped the switch on and it renders fine. I then changed the API level to match my API level (21) and it rendered a bit differently, but again rendered fine.
After much debugging and frustration I discovered that if I implement by own custom drawables for the Thumb and Track that the UI seems to function.
So I was wondering: Has anyone run into this before? Do we know what the cause is?
I wanted to document this in case anyone else ran into problems.
Someone requested layout code. There's not much, but here it is:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Yes I managed to get this figured out, then forgot to update this. Unfortunately I couldn't get it working through Xamarin. Something was messed up and I didn't know what it was and couldn't get an answer from anyone. So: I drew it myself (which I ended up needing to do anyway for my app).
In my layout for the switch I set these two drawables:
android:thumb="#drawable/SwitchThumbTrack"
android:track="#drawable/SwitchTrack"
Then in my code when someone toggles it I have a drawable for SwitchTrackOn as well. If you want, here's some code to make it kind of look like an iOS switch:
SwitchThumbTrack.xml
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#FFFFFF"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
SwitchTrack
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="15dp"/>
<stroke android:width="1dp" android:color="#ffffff"/>
<solid android:color="#0000FF" />
<size android:width="80dp" android:height="30dp"/>
</shape>
SwitchTrackOn
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="15dp"/>
<stroke android:width="1dp" android:color="#color/White"/>
<solid android:color="#4ED164" />
<size android:width="80dp" android:height="30dp"/>
</shape>
Hope this helps!
James
For me, adding the following worked:
android:minWidth="100dp"
android:minHeight="50dp"

Resources