Android radio button style definition - android

How can I make sure that the radio button appearance for 2 different projects is the same?
I copied what I thought were all of the relevant files and code from one project to another, but the radio buttons (and some other features, like the title bar) appear different. It's like the activity_main.xml file is being interpreted differently, or there's a different set of defaults. They have the same target & min sdk, and they reference the same base theme, and have the same activity_main.xml file.
I'm not sure if it makes a difference, but the original code, that has the look I want, was written on the Android IDE that was available about a year ago.
Thanks!

You are definitely on the right track. My first guess would have been the theme and style used. I do not believe the version of the Android IDE will have anything to do with this. I would look a little bit more closely at the themes. See if you have multiple styles defined based on OS versions and make sure you copy all of them. My only other guess is that the theme or style is being updated in the code in one of the projects.

Related

What makes buttons purple in Android studio? Plus other odd behaviours for a newbie

In web development, I see how tags have default themes defined in the browser, and I see how they're applied.
However, with Android Studio's themes, I'm really confused. I can define my custom themes using ?attr/myClass, apply it on widgets by android:theme="?attr/yClass", and then assign a colour to that attribute in my day or night theme files.
But, what baffles me, is—that purple. Where does it come from? When I set the theme header to
<style name="Theme.TestingThemes" parent="Theme.MaterialComponents.DayNight.NoActionBar">
purples come for the not night mode.
When I use other styles that come with "default" with Android Studio, I don't see exactly that purple.
Some themes allow me to set my own colours, but some others don't, like the one that I mentioned.
Worst of all that totally blows my mind is: when I open the theme files in app/res/values/themes/* and app/res/values/colors.xml*, I only see less than 10 themes defined. Yet I see Android Studio suggesting to me a long list of colour names! Where do these come from?
I only use Vim as my text editor. I'm drowning in Android studio. It's cool and powerful, but I require some baby-walking assistance.
A default new project created in Android Studio has a colors.xml resource provided in the project (res/values/colors.xml), where the purple_500 and purple_700 you described are defined.
Any other colors and themes you see that aren't in your own project's files are in the AppCompat and Material Components libraries (defined as project dependencies in default new projects), or they're built into Android itself.
In the Projects panel on the left in Android Studio, if you expand External Libraries, you can see all the code libraries that are imported for your project as dependencies (these are defined in app/build.gradle and downloaded from the Web automatically). Among these dependencies are AppCompat and possibly the Material Components libraries, with their own provided resources within.
You can't modify the contents of the libraries. You're intended to customize by extending (making child styles and themes).
If you want to see where a reference is defined in Android Studio (in XML or other languages like Kotlin and Java), you can Ctrl+Click and it will jump to the line that defines it in whatever file it's in.
I've been developing with Android for a year and have honestly never bothered using material buttons.
You can create your own drawable file for the background of the button and then add that drawable to the back of a regular button in a layout. Don't let things like this frustrate you; there are so many ways of achieving the same outcome in Android :D

Where can I find all Android built in themes

At the moment im using:
android:theme="#android:style/Theme.Black.NoTitleBar"
Which I'm growing a bit bored of, Is there a link you can direct me to that shows me examples of all the inbuilt themes and their names?
I read on another post that there is quite a few so it would be best if there was a website/other source that could show me some previews :)
Thanks for the help!
Your IDE (I know Android Studio does), should show you them.
Otherwise, here they are in raw xml form. https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml
More information on Android Dev docs: http://developer.android.com/guide/topics/ui/themes.html
You can see all the theme names in the manifest.xml. For this see the following snapshot:
Android Studio has a Theme Editor which provides preview function.
User can find all built-in themes inside.
2 ways to open it:
Open a styles XML file, for instance res/values/styles.xml. Then click Open editor near the top-right of file-editing window.
in top menu bar Tools-Android-Theme Editor.
I'm pretty noobish with it all but basically I think there are only two themes. Day/Night and Light. You can select individual parts and change them but as far as I can tell there are only two themes.
As I had a comment that said this doesn't answer the question I will add that you can use Theme.AppCompat.DayNight or Theme.AppCompat.Light in the AndroidManifest.xml or in styles.xml and edit any individual attribute but there are about a million attributes and god only knows what they all do. In my opinion it's a massive oversite by android.

Can I edit a style dynamically?

I'm currently developing an app which should be totally customizable by endusers. Imagine the application has many activities with some TextViews, Buttons, etc.
So the client can create a XML file like this one:
<style >
<h1>25dp</h1>
<h2>30dp<h2>
<actionbar>#cecece</actionbar>
</style>
As you can imagine, for example, there are several TextViews which are always "titles" so they should always take this h1 value.
I know I can parse this XML file and for each textview, apply this style manually, but this is not a good way of achieving this because if I had 3000 textViews, I should manually edit them all.
What I want is to "edit" the actual Style programmatically.
Any tip?
You can't access a resource file in the created APK as they are compiled into it. So your idea to "customizable" styles works only in the following scenario:
your app is a library project
your client uses that library project and create a style which extends/overwrites your own style and compile that into a new APK
You are not clearly telling us if the "enduser" is a user of your app/apk or a customer that can do the above mentioned modifications.
An alternative might be to create your own extensions of TextViews, Buttons etc which can load your style set. You need to create your own style language for that and you need to make sure that the custom views understand and apply them.
A lot of work, if you ask me... I would, in general, suggest to make different themes so that the customer can pick the best suited for them...

Why "Buttons in button bars should be borderless" in Android API Level 15?

I'm developing an application for Android and I recently changed the API level target from 8 to 15, and now Eclipse is warning me when the Buttons are inside Linear Layouts or Table Rows.
The same doesn't happen when the Button is in a Relative Layout.
The warning says:
Buttons in button bars should be borderless; use
style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent)
I can get rid of the warning by following the suggestion or even by suppressing it, but I'm interested to know why this now? What's wrong with bordered buttons?
The borderless buttons are for cohesiveness of design throughout the android platform. It's recommended you follow the guidelines so that the user feels that your app is native and does not stick out like a sore thumb, but there are many cases where it just doesn't make sense, like if it makes your app look unprofessional. If that is the case, you may want to turn off the warning.
To turn off the warning, go to the project properties -> Android Lint Preferences. Search for "border" or "ButtonStyle" and change the severity to ignore on the bottom right.
You can also do this in Eclipse preferences for all projects.
For Android Studio Users:
File -> Settings -> Editor -> Inspections -> Android Lint. Search for "borderless" and uncheck or change the severity.
Here is another simple way to get rid of it.
The compiler is trying to tell you to set the style of the button. So simply add the following style for the Android default borderless style and the error will be gone.
<Button
...
style="?android:attr/borderlessButtonStyle"/>
Here is the proof
In my case adding that style to ALL buttons which were ONLY elements in some linerar layout gave buttons without any borders. After adding style also to the layout I got buttons separated with small edges exsacly like in some epements of my (4.1.2) android interface eg. like in dialog possitive/negative buttons. It worked correctly. Standard Holo buttons are ugly but with that styles they look "professional";-)
You can add this code to fix it " style="?android:attr/borderlessButtonStyle"/> "
but if your emulator is too old then that problem can occur aswell.Try to change your emulator Pixel 6 Pro.

Create a custom style

I'm looking at how to give an app that I develop and deploy it's own look and feel. So I read about the Style and Themes on developer.android.com. After some initial success with text color, text size, background color... I seem to get stuck at changing buttons, toggle buttons... It appears to me that to change the color of a button a .9.png file must be created (possibly for the different dpi's). Looking at the artwork in the default style, I see a large number of these .9.png files. To have a consistent style they should all be updated.
Is it correct to say that defining a new style involves modifying/recreating the .9.png files?
If no, how should one go about modifying the style of these .9.png based elements?
If so, are there any tools that assist with creating a custom style? And are there any style packages that can be downloaded/purchased?
I'm not sure it's a good idea to give a new look to every UI control in your application unless you are a very experienced designer. Probably, we can't beat Google designers at their craft and it would be better to comply with existing styles adding some cool features instead of changing button colors at random.

Categories

Resources