I want to moving all theme related xml code to compose file. There is a splash screen xml code, is it possible to let it in compose style?
<!-- Splash screen theme. -->
<style name="splashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
#Composable
fun splashScreenTheme() {
}
As of Compose 1.0.1 / August 2021, there is no way to do this completely in Compose. I am currently using the XML/android:windowBackground based solution in the OP for my app which is pretty much entirely Compose otherwise.
However, note that Android 12 is introducing a SplashScreen API which lets you define a splash screen consisting of an adaptive icon and solid background colour.
Also, remember that things like date/time pickers are still not yet available natively in Compose, so if you use the Material Components library for that, you will still need the XML style files.
Related
Need to implement UI like in the following picture
What is the best way to do it? I found out about "material design" and PhoneGap. I'm new in android development, so i dont know the best practices and I want to choose best path to follow. What exact layouts I should use, RelativeLayout or TableLayout or other, how to apply styles to ui elements, borders, backgrounds and so on.
Should I use styles or build-in attributes? Can I find an example code somewhere, may be good tutorials or open-source applications? I found a lot of samples in a book by Deitels and in GitHub, but it's all look like native android ui, not like web or flat ui.
Flat Material UI design Android:
As per I understand from you question that you want the flat Material design for Android Native UI.
So for that please follow the below process:
Let’s jump right into two key features of material design: Themes and Colors!
Themes let you apply a consistent tone to an app, and developers can choose between dark or light themes (see Figure 1 and Figure 2).
Custom colors can also be defined using theme attributes which are then automatically used by the app for different components e.g colorPrimaryDark for the Status Bar and colorPrimary for the App Bar (see Figure 3 below).
Add the Light theme to our app and customize some of the colors in res/values/styles.xml
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#3F51B5</item>
<!-- Light Indigo -->
<item name="colorPrimaryDark">#3949AB</item>
<!-- Dark Indigo -->
<item name="colorAccent">#00B0FF</item>
<!-- Blue -->
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>
The app should now look like this:
For more information clicks on the following link.
create an Android material design app
How can I change the color of the animation?
The color is based on your accentColor in your AppTheme.
To change it, change your AppTheme (generally in res/values/styles.xml) to:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">#F00</item> <-- change to color
<!-- Status Bar color -->
<item name="colorPrimaryDark">#000</item>
<!-- Details color -->
<item name="colorAccent">#000</item>
</style>
Beware it's an global app change, every scrollview bounce animation will have this color.
To change only the overflow animation color, use android:colorEdgeEffect. Otherwise it will be inherited from the colorPrimary in AppTheme.
The accepted answer should be changed to specify colorPrimary instead of colorAccent.
See answer here: android lollipop scrollview edge effect color
Put this inside android/app/src/res/values/styles.xml
<item name="android:colorEdgeEffect">#E53644</item>
if someone is using expo managed app, it's not supported by expo yet, but there's a workaround.
you'd need to expo eject -> to transition to bare workflow. then as said above within android/app/src/res/values/styles.xml add
<item name="android:colorEdgeEffect">#E53644</item>.
now the worst part which took me hours to figure out - you'll have 2 themes generated by default the AppTheme and Theme.App.SplashScreen, it didn't work until I've added it to splashscreen one :/. I've added it to both themes just in case. note that this specific change will work only when you run android specific native build npm run android, for more please read this
I'm using Expo managed workflow + react native paper with Material UI v3 and in debugging the color of the "ripple" was purple.
But luckily, when I test it over the Google Play Store, it was based on the primary color (or primary container color).
PS: I had similar issues with the color of dialog buttons and the app icon being not shown correctly.
I want to create several button styles instyles.xml. I want to support API 19 and higher so I would like to create button styles for both API. What I am doing:
I've created custom style in stylex.xml:
<style name="AppTheme.ButtonGreen" parent="android:Widget.Holo.Button">
<iten name="android:textColor">#color/accent</iten>
<item name="android:background">#color/primary</item>
</style>
In facy the color does not change. Can you help me with theming and give some basic attributes like: background color, text color etc. cause those does not work (only font color works).
I have also implemented style for v21 in styles (v21).xml:
<style name="AppTheme.ButtonGreen" parent="android:Widget.Material.Button">
<item name="android:textColor">#color/primary</item>
<item name="android:background">#color/text_icons</item>
</style>
But here I need font color, background color, elevation, font size etc. (only font color works).
Generally I guess I am doing something wrong. Can you guys help me style those buttons for different API?
Please read this article
https://www.androidcookbook.com/Recipe.seam?recipeId=3307
and this issue on StackOverflow:
How to create custom button in Android using XML Styles
I think the first one would be enough for your actual needs.
If you have question, please feel free to ask.
EDIT: if you still feel stuck - maybe it would be good to create an image and set it as ImageButton.
http://angrytools.com/android/button/
http://dabuttonfactory.com/
Or try to find issues abot using Material Design in lower APIs. This might be helpful: how to use material design features in api lower than 21 in eclipse?
you have to use background instead of backgroundtint
I'm developing an app for Android wearables. I want to create a layout working on both round and square screens. Therefore I'm using BoxInsetLayout.
I also want to use a CheckBox from Material Theme. Therefore I'm using a custom theme derived from Theme.AppCompat.Light.
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
The problem is that BoxInsetLayout is not working properly on round screens. I'm having the same issue as described here but the solution mentioned there is not working for me. The relevant code parts are the same except the theming part.
When I switch the theme to Theme.DeviceDefault I only get the CheckBox from Holo.
Try adding:
<item name="android:windowOverscan">true</item>
to your theme. It is necessary for dispatching insets.
I set the application theme using the following style
<style name="Background1" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#drawable/bigl_2</item>
<item name="android:windowNoTitle">true</item>
</style>
using this method :
setTheme(R.style.background1);
Here my requirement is I want to change the theme with a bitmap image, how can I do it at runtime?
Thanks
You may want to have a look at the same question: android dynamically change style at runtime
As it seems to me, the matter is that generic style attributes can force screen re-layouting, so there is no API to change styles at runtime - you need to create screen anew (the same approach is dictated for landscape/portrait screen orientation changes, where Activity is re-created and large brains of Android system architects invented savedState in onCreate() to easy (complicate?) that process, and then invented Fragments to easy that even more))
So, changing styles generally means changing layout. But you can change Theme attributes at runtime (per the link above - I haven't tried myself), and it will work since it doesn't need re-layouting.
As a workaround, since you will need to recreate views for new layout, you can simplify code by applying different Theme, see the link.