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
and then apply it on widgets by android:theme="?attr/yClass"
, 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/*
andapp/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'm facing my 1st mobile development task, and really frustrated. 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. S.O.S.
CodePudding user response:
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 a so many ways of achieving the same outcome in Android :D
CodePudding user response:
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.