Android System Resources Get Text dynamically - android

I would like to set some specific system settings of android within my application.
Is it possible to get the text and maybe also a description of the settings resources by code?
For instance I would like to allow to change this setting:
android.provider.Settings.System.SCREEN_BRIGHTNESS
In the android settings it appears Brighness. This resource is localized as well, so I do not want to do the same thing within my appliacation.
I would like to create a button and insert the text dynamically, if possible.
If someone has a hint were to look at, please help.
Best Regards,
Patrick

android.provider.Settings.System.SCREEN_BRIGHTNESS In the android
settings it appears Brighness. This resource is localized as well, so
I do not want to do the same thing within my appliacation.
See this: Settings.System. If you want the value localized, use an integer resource in folders with language and/or locale qualifiers. See Integer Resource and Alternative Resources
I would like to create a button and insert the text dynamically, if
possible.
Define as much of the layout as possible in xml, calling setContentView() on the name of the xml file. The button can then be referenced after the call with (Button)findViewById() using the id as given in xml. You can then set text dynamically and modify the widget further in code. See Layouts and TextView setText, which works for Button since Button extends TextView.
Hope this helps.

Related

Doesnt understand attribute ?android:attr/textAppearanceLarge

i am new in android development, i want to ask about the meaning of this snippet of xml code android:textAppearance="?android:attr/textAppearanceLarge". Does android framework will determine by itself the size of our text and choose large text relative to their choice?
I have tried to look up from this attribute declaration, but there is nothing that explain the property that will assign to text, and i also confuse by "?android" at the start of property.

Android resource vs hardcoding

I know using a resource is good for redundant uses like any label that is generic across a platforms application but are there any other benefits to using a resource instead of hard coding?
for instance I have a button that is only in one view, is there a benefit to using a string resource for the buttons text even if it is one button that is only in one place in the entire app?
Otherwise I feel like its easier to go in to the one specific view to find the button and change the text if i need to rather then scrolling through an entire resource file to find one string resource.
There is more than one reason for using strings.xml than hardcode it. Please read the localization documentation. It allows you to easily translate text into many languages as you provide.

what happen if do not put text files in string.xml in android?

i did not put some text in string.xml and there is a yellow alert symbol in side of Textview field. i want to know does it have problem and what happen, if do not put texts in string.xml in android?
Well, setting your text directly on your layout file can be a source of future problems and its not recommended.
Consider this scenario: You use the same string "Foo" in many layout files and then you decided to change to "Bar". If you have hardcoded that, you will need to make changes in all layout files and there might be a chance to leave some inconsistent text. But if you place it in the strings.xml file, you will have only to change in one place.
Also, if you want to add translations to your app, the Android system can handle it automatically for you if you use the strings.xml.
You might want to take a look here and here.
Nothing will happen.
string.xml used to:
localization
res/values-fr/strings.xml
res/values-ja/strings.xml
ease of editing and to save memory when reusing.
I Recommend you to put text files in string.xml
Whilst it will not cause a problem in the short term, it is not good practice and will cause you issues in the future if you decide to support multiple languages.

CheckedTextView Attributes ID and checkMark

Just start developing with android and think instead of reading a book a webinar could be better because a webinar could also teach me short ways and how an android developer thinks when writing the code but now got a problem
<CheckedTextView
android:id="#android:id/text1"
android:checkMark="?android:attr/listChoiseIndicatorMultiple"
</>
I dont understand the above code up to now see lots of different id definitions some of them was for resources and start with #resource/name, and some of those id definitions was like #+id/name just for creating a new id for the component but this time it is using android:id/text1 and I dont understand why it is using it in that manner
Besides, the checkMark thing make me confuse more what are all those ?android:attr/listChoiseIndicatorMultiple means?
Could you please explain me and show me some resource where can I find all those magic attributes so I can cope next time by myself and hope someday can answer other newbie questions
Thanks a lot in advance, and all comment will be appreciated.
Well, reading the docs has always been helpful to me:
Android Developer Site
XML Layout specific docs
#android:id/text1 is just a format used when the id has been previously defined. When you put a + in there that means the framework should create the resource id if it doesn't already exist.
It's normal to use #+id/thisid when defining a new view in a layout, and then use #id/thisid to reference the aforementioned view from another part of the layout (say, in a RelativeLayout where you need to tell one widget to be below another).
A question mark before the ID indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute.
#android:id/text1 basically this is used when you create any android component like button, layout, textviews etc.
but when you need any external component which is general for different platform like any color, image etc then you can declare it as #resource/name.
actually there is nothing different just keep one thing in mind that in #android:id/text1, id will simply work as an class name will contains other objects like textview, imageview or any other.
now if you declare #resource/name then in that also instead of id class name will be resource. actually when you will use it in java then these(#android:id/text1) will be converted into object hierarchy.

Modifying styles programmatically

In an Android application I am writing, the styling for my various TextView elements is defined in an xml resource. I would like enable the user to change certain styles such as android:typeface using a PreferenceActivity.
Is there a way to modify a style resource programmatically such that all associated widgets will update correctly? If not, must I manually select all widgets by id and change their styling?
Don't know whether you've found it but the Cubewallpaper sample uses preferences and that appears to do it all by hand in the onSharedPreferenceChanged event.
You can keep the preference keys in a resource file but that's about it it would appear.

Categories

Resources