Attribute can not be used when did android theme development - android

I'm studying how to use custom theme in android application. After I create a style.xml, and input below xml strings.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Light">
<item name="editTextColor">#00f</item>
</style>
</resources>
Eclipse gave an error when I run the project, it can not find the attribute "editTextColor", but in the sdkpath\platforms\android-17\data\res\values\themes.xml, it does use "editTextColor" attribute.
When I changed the editTextColor, the application works.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Light">
<item name="android:editTextColor">#00f</item>
</style>
</resources>
Can anyone tell me why please? Thank you very much.

While inside sdkpath\platforms\android-17\data\res\values\themes.xml, it is referencing the value directly means inside android platform itself, but while you are trying to reference it inside your application you have to reference it using android:editTextColor because you are using it outside android platform itself and overriding its value.Hope you got some idea.

Related

Set default font family for Android app

I'm new to Android studio and I am wondering where to set the default font family for Android app in Android studio after reading the accepted answer here.
I have tried to put the code in activity_main.xml and AndroidManifest.xml but it does not work.
Any help would be appreciated!
Thanks KDeogharkar!
Looks like I would have to add the code inside of styles.xml in values folder. It worked :)
/res/values*/themes.xml
Pick any parent theme to extend here
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">#style/RobotoFont</item>
</style>
<style name="RobotoFont" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif</item>
</style>
</resources>
Then in your app manifest
android:theme="#style/AppTheme`"

Android Failed to find style in current theme

in this simple designed Theme, Android could not find numberPickerStyle ino that and i get this error:
Failed to find 'numberPickerStyle' style in current theme
My theme is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Tsms" parent="#style/Theme.AppCompat.Light">
<item name="numberPickerStyle">#style/SampleTheme.Tsms</item>
</style>
<style name="SampleTheme.Tsms" parent="#style/Theme.AppCompat">
<item name="numberPickerStyle">#style/NPWidget.Holo.Light.NumberPicker</item>
</style>
</resources>
how to fix and resolve this problem?
I am assuming you copied your code from this StackOverflow answer. numberPickerStyle would be an attribute that is defined in your app. The code that you copied from the answer does not work. You would need to define an attribute in XML for the error to go away but that still would do nothing for you.
You can't style a NumberPicker. android:numberPickerStyle is private (see this issue).
Unfortunately, you can't style it. The styles and styling attributes
for NumberPicker are not present in the public API, therefore you
can't set them and change the default look. You can only select
between light and dark theme. source

Android App Custom Background

I feel like this is listed somewhere and is extremely easy but I cannot seam to find a straightforward answer. How do you set a custom background image. For instance set a PNG as the default background for my app instead of the black screen. Manifest, Layout, Main code thing? An example would be extremely amazing.
xml/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Light"> <!-- Or any other parent you want -->
<item name="android:windowBackground">#drawable/yourcustombackgroundimage.png</item>
</style>
</resources>
and use this style in the manifest file.
<application android:theme="#style/MyTheme">
For those of you that are still looking to do this, the correct way to do it has changed slightly. Piggy-backing off of 500865's answer, here is the adjusted code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:background">#drawable/dummy_background_image</item>
</style>
</resources>
Basically, you have to change windowBackground to just background, you have to include the line about xmlns:android, and you should (although not required) remove the .png extension.

How can I set the Background of all my activities in styles.xml

I am trying to customize my styles.xml file to display the same background for each one of my activities.
I tried this code in my styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="android:Theme.NoTitleBar">
<item name="android:background">#drawable/mybg</item>
</style>
</resources>
this worked pretty well untill I put a TextView in my activity.. Every View I put in my layout get the same background, and that is really annoying
What is the best practice to set only the background of the activity?
I think I have found my answer:
<item name="android:windowBackground">
fits all my needs
May be you can do it like this :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="yourstylename">
<item name="android:background">#drawable/mybg</item>
</style>
and set this style to all your activities root element in xml file.

How to access style.xml values

I have styles.xml with Style definition like this:
<style name="Style1">
<item name="titleColor">#color/red</item>
<item name="lineColor">#color/light_red</item>
</style>
I'd like to access "titleColor", "lineColor" attributes values programmaticaly. Is it possible somehow to do?
Would appreciate your help very much, cause already spend hours trying to find a solution.
The answer is here how to get Theme attributes values
Yes, do it like that:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Style1">
<item name="titleColor">#color/red</item>
<item name="lineColor">#color/light_red</item>
</style>
</resources>
Then Build the Project, after Building you can access the values with
R.style.Style1...
edit to clarify:
button1.setBackgroundColor(R.style.Style1.titleColor);
I think you can use following code in order to access the style1,
style="#style1/titleColor"
style="#style1/lineColor"
That is all.

Categories

Resources