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...
Related
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
I have to make a new design for an Android App, but I only have to create the visual part (native Android). The app logic would be created by another guy based on what I present to him.
My question is? How would this be managed correctly? Do I have to make the XML's of each layout? How could I show the other person my progress?
What things should I consider when doing this?
Thanks
You need to mock the app first (create a prototype) as suggested by NoChinDeluxe. Then if you guys go ahead and decide to code it, the answer to your problem is separation of responsibilities. As Jeffrey said UI work is not only about layouts, but code as well. What I would suggest is that you and the other guy get together first and define some contracts (interfaces) that will allow you guys to split the work and work in parallel. Therefore, he can create the business logic of the app without worrying about the UI implementation. You, on the other hand, will have to mock that business logic he's implementing at the beginning so it doesn't block your UI work.
you could create layout XML files for all the Activities/screens, using resources (icons, etc as suggested by #NoChinDeluxe). However since you'd want to run the mock app, you might want to also create a "throw-away" Activity that allows you navigate to different screens of the app. Here you can add a number of buttons and when you click on each button, your app shows a specific activity. This way, you will be able to show your colleague all the screens you have created. I hope this helps.
This may not be what you want to hear, but creating Android layouts isn't a design task. They are closely tied to the code, and the design of them is going to depend on how the engineer chooses to implement the app.
Here's an example. You might have a grid with 4 cells. You could use a RelativeLayout, a LinearLayout, or GridLayout, or a GridViewLayout. Which will use choose?
I'd suggest providing your engineer with mockups and graphical assets where required. Let him / her take those and create the layouts. If you want to create layouts as a (visual-only) reference for engineering, great, but it's certainly a non-optimal tool for that task.
Things You will consider when doing visual part:-
You have to work on the resource folder of your application
Layout : All Layout you have to prepare.
Drawable : Images and drawable .xml.
Inside Values folder you will find
dimen.xml : For different devices dimen you can set.
string.xml : You can store string for hint or other purpose.
style.xml : For designing or theme or custom design.
color.xml : Color which are going to used in the application.
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.
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.
I'm developing an app for text reading. I'm trying to increase the options for my users to customize the appearance of the text and the app itself. Creating multiple styles in my resources folder and switching among them at runtime seems simple enough using the view constructors that take a style parameter.
However I'm also considering going one step further and creating a style editor in my application that allows users to have full control over their experience.
I think that doing this using Android styles is basically out of the question, since the style ids are generated at compile time. I'm considering creating custom views that are light wrappers around the views that I need styled, manipulating the AttributeSet in the view constructor to apply my styles.
How should I dynamically create and apply styles to my views?
your approach is quite right as i tried several posts in several places, if you don't do it yourself, it wont be done :-) Android does not support dynamic theme as it seems.
I wanted mine to be downloadable as a plugin, you need, as you say create a wrapper and be able to extract extra parameters from the AtrributeSet OR add an extra HashTable parameter with the attributes you want to override.