Set default font family for Android app - android

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`"

Related

Android Style Split does not work, explanation needed

i am trying to change the style of the action bar in android.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="GoetheTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/GoetheActionBar</item>
</style>
<style name="GoetheActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/base_color_dark</item>
</style>
So yeah, thats what I got. Now I have put the application theme in the android manifest to the created one (GoetheTheme). But the ActionBar does not change. If I set it to #GoetheActionBar, it does. Why does GoetheTheme style don't take the GoetheActionBar style?
Can please someone explain me the style system? I really dont get it.
Thanks in advance
Sorry, my very bad. I found out, I have to use a different parameter as parent ^^
I took a Light theme based one not android specific.
Correct:
<style name="GoetheActionBar"parent="#android:style/Theme.WithActionBar">
<item name="colorPrimary">#color/base_color_dark</item>
</style>
<style name="GoetheTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/GoetheActionBar</item>
</style>

Material theme not applied correctly on pre-21 devices

I understand that to correctly use some of the Material theme design patterns for pre API-21 devices, I'll have to include two style folders.
The theme is applied correctly on my Nexus 5 (lolipop) device, but when I run my application on a pre API-21 device (I'm using my Samsung Galaxy Note, API-16), I'm getting a blank, black screen. The application works, as I can interact with the activity (press buttons, use the keyboard, etc), but I can't see anything.
Here is my res/values-v21/themes.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="AppTheme">
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryDark">#color/darkgreen</item>
</style>
</resources>
and here is my res/values/themes.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
</style>
</resources>
and I've included this line inside my manifest file under <application>:
android:theme="#style/Theme.MyTheme"
Am I not supposed to use the AppCompat theme for pre-lolipop devices? I'm using the v7 support library.
Any help is appreciated.
Change your res/values/themes.xml in:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryDark">#color/darkgreen</item>
</style>
Then remove the same theme (name="Theme.MyTheme") from res/values-v21/themes.xml

How to change ActionBar.Tab's strip color?

I want to change the strip color of ActionBar.Tabs and for that I am following this tutorial.
But there are some errors that I cannot figure out. Here is the code in style.xml
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="FindMyTrain.ActionBar.Tab">
<item name="android:background">#color/red</item>
</style>
<style name="FindMyTrain" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarTabStyle">#style/FindMyTrain.ActionBar.Tab</item>
<item name="actionBarTabStyle">#style/FindMyTrain.ActionBar.Tab</item>
</style>
</resources>
And these are the errors:
And I have no idea what am I doing wrong or what do these errors even mean. Any help would be appreciated. Thanks.
For the actionBar color, I suggest you use the Android asset studio here. It's a easy way to change the actionBar color and style. All you need to do is generate the style you want, download zip file, unzip it, copy all files (drawable folders) into your res folder and change your app theme in the AndroidManifest.xml to what you just generated from asset studio.
Try this.Make sure your build target is set to 13.
Project Properties -> Project Build Target = 13 or above.
<style name="ActionBarTab">
<item name="android:background">#color/red</item>
</style>
<style name="FindMyTrain" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarTabStyle">#style/ActionBarTab</item>
<item name="actionBarTabStyle">#style/ActionBarTab</item>
</style>

Attribute can not be used when did android theme development

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.

What do i have to do to make a style for an activity that just affects the textviews?

Actually i have two questions.
Question 1.
I have made a style for a TextView
http://pastebin.com/q9hj26JX (Couldn't paste xml code here, it just went invisible)
To add this style i do:
http://pastebin.com/QdGmjQ0z
But instead of doint this, there must be a way to add this style to all the TextView in an activity? I have seen something like "Widget.TextView", but i have not found any good tutorial or documentation on it yet.
So can someone please give me an example, if it is possible.
Now for question number 2:
I don't get any intellisense while creating styles. Does it not exist for style creation?
Thanks in advance!
Please red about THEMES in android http://developer.android.com/guide/topics/ui/themes.html
The THEME is a style for whole activity and sets in Android Manifest.
Hope, it help you!
UPDATE:
Try this code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="small_describing_text" parent="#android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_marginTop">0dp</item>
<item name="android:textSize">10dp</item>
<item name="android:textColor">#FF0000</item>
</style>
<style name="MyTheme" parent="android:Theme.Light">
<item name="android:textViewStyle">#style/small_describing_text</item>
</style>
</resources>
Don't forget add this theme in Manifest for your activity!!!
You might want to have a look at my blogpost where I've explained theming and styling: http://aproblemlikemaria.wordpress.com/2011/09/26/theming-and-styling-in-android/

Categories

Resources