I use mapsforge in my app. I want to use different theme for create different font size. I create different them and save in asset folder and i change my theme with below code but the program cnanot load true theme! I want when click on A button, load xhdpi but when click on this, load a theme with vry small font!
File f=new File(destination,"xhdpi");
mapView.stRenderTheme(f);
in xhdpi theme, i set big font(30) but when i run this code theme change to small font and i dont know, the program of where load this theme! :D
and in the last, i think, mapsforge or my app use a default theme for changing theme but im not sure and i dont know where is the problem!
Thanks for advise and your help.
Try this:
mapView.setTextScale(3); // default scale size is 1
if it works as works for me , you can give scaling as an option to user!
Related
I have a logo on my splash screen and two files:
logo_night.png and logo_day.png
How can i change this logo that will change depending on the theme of the app using these two files?
The usual way is to use a night resource qualifier, so if you're using a dark theme it pulls the named resource from the equivalent night folder if it exists there.
You have three basic options with this I think:
just call them both logo.png, but put one version in drawable and the other in drawable-night. That way, whenever you refer to #drawable/logo it'll pull the correct version depending on the theme. If you have multiple density versions, in drawable-hdpi etc, you'll need them in drawable-night-hdpi etc. (the qualifier order matters)
if you're making your splash in the usual way, where you create a splash drawable with a background layer and your logo drawable on another layer, you could just make a night variant of this instead (in drawable-night). Each version can explicitly refer to logo_day or logo_night and you can just keep those PNGs in the normal drawable folder
or you can make a night version of your splash theme, and explicitly set the background to the dark version of your splash drawable instead. Both your splash drawables can stay in the normal drawable folder
So basically, something's gotta get a version in a night-qualified resource folder, so it can provide an alternative resource for dark mode. It's up to you which resource in that hierarchy you want to make the night version of (or you can do it for all of them if you want).
Also bear in mind that your splash theme (if you're doing it that way) follows the system's dark mode setting. If you're implementing a toggle in your app, and you set it to dark mode, the splash will still show up as the light variant if that's what the device is set to. That theme is set before your app starts and gets to work out if it should be in dark or light mode
Since you are using png format. You can call .getTheme() on context object to get current theme, make an if statement to decide which png to show.
For example in activity you can get theme by just calling getTheme() because this.getTheme() is implied.
Other possibility is to switch to vectors where you can define different colors for different themes they will change automatically when user changes theme. This is probably better and more scalable solution. You can find much more details here.
I am trying to do a drawer activity with Android Studio and I'm wanting to personalize the icons used. I've downloaded the icons I want to use and for the most part, it's okay.
In fact, I can modify all the android:icon icons but I have no idea how to modify the app:srcCompat icons. I don't know how to detect the image I want to use in this case...
Do you know how I can do it? Could you explain this to me?
Thanks a lot!
Edit: The file I'm working on as a base is the generated project with Drawer activity as the main activity. For example, if I wanted to modify the icon in the nav_header_main.xml file, how could I do to have my image (.png) transformed in a way detected by Android Studio as compatible with srcCompat
Ensure your image file is in res/drawable folder(or drawable-xhdpi/xxhdpi, determined by your design)
Refer it by app:srcCompact="#drawable/$IMAGE_FILE_NAME" in your xml.
Then you should see what you want.
Please check the doc to further understand the official usage.
Well... I was blind! I was wondering how I could add my icons but they were, I was just mistaking on the address... #android:drawable/... is obviously not #drawable/... but I didn't notice. So be aware that there is a difference and it'll be okay I think!
I downloaded some icons from material.io but they only offer the icons in black. I saw a youtube video where they use to allow you to choose the color. Anyway, I am trying to change the colors of the icons to white. I am not having any luck. I tried to change the fill color in android studio but it doesn't work. Any assistance would be appreciated such as exact code and files to add the code to. Thanks.
simply you can use
android:tint="#android:color/white"
You can directly download these images in Android Studio.
res > right click > New > Image Asset and select
Icon Type : Action Bar and Tab Icones
Asset Type : Clip Art
Theme : CUSTOM
And you can select any clip art that you want, select the color, padding, etc ...
As mentioned before, the material.io icons can be downloaded directly with Android Studio. This solution shows the importing of vector asset icons which are easier to manage since they are stored in a single location (res/drawable) vs. image assets that will have each icon stored in specific density folders (hdpi, xhdpi, etc).
expand the "res" folder
right click drawable
hover over "new"
select "Vector Asset"
click the image next to "icon"
select desired material.io icon
Name the icon what you would like
select "next"
Now you will have two options of setting the icon color
In the layout by using the android:tint attribute of an ImageView. This is my preference because the icon can be viewed prior to runtime.
or
In Java.
imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white),
PorterDuff.Mode.MULTIPLY);
https://material.io/icons/ actually does let you download icons in white.
But, depending on what exactly you want to do, there are a few options. If you simply want white icons (and not to change them at runtime), you may find this plugin for Android Studio useful: https://github.com/konifar/android-material-design-icon-generator-plugin
It allows you to generate the material design icons right in Android Studio, in whatever color you want. Another alternative for downloading these icons in different colors is https://materialdesignicons.com/.
If you do want to color the icons at runtime, try something like this:
imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white),
PorterDuff.Mode.MULTIPLY);
You can download white icons from material.io. also look at themes and theme overlays
Instead of android:src
I use attribute android:foreground
android:foreground="#drawable/ic_add"
For those not getting what they want yet try changing the PorterDuff mode, the following is what did it for me
imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white),
PorterDuff.Mode.SRC_ATOP);
maybe
app:iconTint help you, I am writing this because of the following reference.
Material Design 3
I am writing app with android:minSdkVersion="14". Everything went fine until I tryed to add support for tablets.
When I created values-sw600dp folder and copied there the default dimens.xml file from values folder and tried to run the app on tablet, it started behave differently even when those dimensions file were identical.
ActionBar was gone, getActionBar() started to return null, EditText fields are orange framed instead of that blue underline, whole app design now looks like its on android 2.0.
On smaller devices where it still used default values folder everything is ok.
For testing, I tried to lower the 600 threshold (in values-sw600dp) to 300 to force this folder to be used even on smaller devices and result was same. ActionBar gone etc...
Sorry for english and thank you for answer
Ok I found solution to my problem. I accidentally coppied line:
<style name="AppBaseTheme" parent="android:Theme.Light">
into my dimens.xml file in folder values-sw600dp, which caused application to use Theme.Light instead of my default theme Theme.Holo.Light.DarkActionBar in folder values-v14. I donĀ“t know how it got there but I am glad I found it.
Is possible to make the app use different drawables after choosing a theme in Android?
An explanatory example:
i have a layout which background uses a reference to: "#drawable/backgroundsolid", that is image backgroundsolid.png in res/drawable-mdpi.
I want that, if the user choose "Glass" theme, the reference stays to "#drawable/backgroundsolid" but the resources folder is changed to res/drawable-glass, which contains a different backgroundsolid.png image.
Is it possible to set this programmatically? Thanks a lot!
You can set it programmatically by using view.setBackgroundResourceId(). I am not sure if you do it the other way which is let android pick the right theme for you. Maybe someone else has a better answer