I wan't to change all text colors to green. Is there a way to do this aside from copy-pasting android:textColor to every editText/TextView in the xml file? Or probably change the default color to green instead of black. Any help, Thanks :D
You can create style and apply it everywhere or you can extend android TextView which will have green color as standard color
The easiest way would be to add this to your app's theme definition:
<item name="android:textColorPrimary">#ff00ff00</item>
You can give a literal value or a color resource (#color/foo)
Yes, there is a very simple way to achieve this.
In AndroidManifext.xml, put this line in application tag
android:theme="#style/CustomTheme"
And define CustomTheme in style.xml under value folder
<style name="CustomTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:textColor">#color/app_black</item>
</style>
you can create custome style like this in styles.xml
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:capitalize">characters</item>
<item name="android:typeface">monospace</item>
<item name="android:textStyle">bold|italic</item>
<item name="android:shadowDx">1.2</item>
<item name="android:shadowDy">1.2</item>
<item name="android:shadowRadius">2</item>
<item name="android:textColor">#F57025</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">5pt</item>
<item name="android:shadowColor">#000000</item>
</style>
<!-- Custom Style defined for the buttons. -->
<style name="CustomButtonStyle">
<item name="android:textColor">#android:color/darker_gray</item>
<item name="android:textSize">30sp</item>
<item name="android:layout_width">100dp</item>
<item name="android:layout_height">38dp</item>
</style>
And in manifest define that style
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Related
I'm currently trying to implement themes into my application, and I'm running into issues when trying to style my Dialogs.
<style name="MyTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:colorBackground">#color/background</item>
<item name="colorPrimary">#color/colorPrimary</item>
...
<!-- AppCompat Dialog Attributes -->
<item name="dialogTheme">#style/AppCompatDialog</item>
<item name="alertDialogTheme">#style/AppCompatAlert</item>
</style>
For example, MyTheme sets the colorPrimary and colorBackground correctly, which works fine in most areas of the app. And when I need to reference them I'm using them like this.
<LinearLayout
android:background="?android:colorBackground"
...>
<TextView
android:id="#+id/title"
style="#style/TextAppearance.AppCompat.Display1"
android:background="?attr/colorPrimary"
... />
However, when I'm styling my dialogTheme and alertDialogTheme, the color seems to default to something else.
<style name="MyAlertDialogStyle" parent="Base.Theme.AppCompat.Dialog">
...
<item name="android:background">?android:colorBackground</item>
</style>
This will not use my defined colorBackground, but instead some light-grey ( default?) color.
Here is an example of the result.
<style name="MyAlertDialogStyle" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowTitleStyle">#style/MyTitleTextStyle</item>
<!-- Used for the buttons -->
<item name="android:colorAccent">?colorAccent</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">?colorAccent</item>
<!-- Used for the background -->
<item name="android:background">?android:colorBackground</item>
</style>
Left side ("Desired") is using normal colors such as #color/colorAccent and the right side ("Result") is what happens if I attempt to use the theme colors ?colorAccent.
How do I reference my theme's colors in styles correctly?
Also, somewhat related question, I'm trying to style my toolbar, but it's having no effect.
<style name="MyTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar" >
...
<item name="toolbarStyle">#style/toolbarStyle</item>
</style>
<style name="toolbarStyle" parent="Base.Widget.AppCompat.Toolbar">
<item name="android:background">#drawable/header_background</item>
</style>
Any idea why this isn't working?
Thanks!
I was able to at least theme the background of dialogs in API >= 23 by setting this attribute in the Activity's Theme:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:colorBackgroundFloating">#color/gunmetal</item>
</style>
Then making sure your activity uses it in your AndroidManifest.xml:
<activity
android:name="package.your.YourActivity"
android:theme="#style/AppTheme"
...
When extending DialogFragment use AppCompatDialogFragment instead and in your theme
<style name="YourAppTheme" parent="Theme.AppCompat">
<item name="colorBackgroundFloating">your_desired_color</item>
</style>
without the android prefix.
Tested for API 21+
I want every text in my app to be white.
This is what I did:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textAppearance">#style/MyTextViewStyle</item>
</style>
<style name="MyTextViewStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#FFFFFFFF</item>
</style>
And in the manifest I set this attribute of the application tag: android:theme="#style/AppTheme"
Why won't the text color change?
You can try in this way:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">#style/MyTextViewStyle</item>
</style>
I think this might help. Use this for your textView style
<style name="MyTextViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">#FFFFFFFF</item>
</style>
This should work.
I want to change text size of action bar item.
here is my style.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/menu_text</item>
<!-- Customize your theme here. -->
</style>
<style name="menu_text">
<item name="android:textSize">20sp</item>
</style>
this works on android 5 but on android 4 the text size is default and does not change.
in my Project folder res/styles AppTheme has a comment as below,
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
So you can do it with your app Theme. I have done it via below code,
<style name="Theme.YourTheme" parent="android:style/Theme">
<item name="android:actionBarStyle">#style/Theme.YourTheme.Styled.ActionBar</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar">
<item name="android:titleTextStyle">#style/Theme.Viadeo.Styled.YourTheme.TitleTextStyle</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">12dp</item>
</style>
Hope this helps you.
I am trying to change the text color of a action menu item on the action bar. Using app compat. Also the overflow icon doesnt change too. Here is my custom styled styles.xml files.
res/values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the default namespace affects API levels 7-13 -->
<item name="actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the default namespace affects API levels 7-13 -->
<item name="background">#drawable/bg_action_bar</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
res/values-14/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/bg_action_bar</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
res/colors.xml
#F3F3F3
The text color still black doesnt change to white. Has anybody successfully changed the action menu text color. Please suggest some insights. I am testing on 4.4 Nexus5 device.
Use
<item name="android:actionMenuTextColor">#color/font_half_white</item>
// added style directly
Instead of
<item name="android:actionMenuTextColor">#style/MyActionButtonStyle</item>
in res/values-14/styles.xml
In res/values/styles.xml
<item name="actionMenuTextColor">#color/font_half_white</item>
I used a Red Color for testing. See the Action menu Item Home that is red in the snap
Edit:
Full Code
In res/values-14/styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionMenuTextColor">#color/red</item>
</style>
</resources>
Then in res/values/stles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
<item name="actionMenuTextColor">#color/red</item>
</style>
</resources>
In manifest
android:theme="#style/AppBaseTheme" >
Another snap
You can use this to change the text of the Action Bar irrespective of your appcompat version.Give the desired color's hex code and add this in the onCreate().
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>Some Title</font>"));
Check that in your layout xml file you don't have an android:theme attribute specified for your <Toolbar>, which would have priority over the main theme
Override your actionBarStyle attribute as pointed out everywhere over the internets.
How do i change the Overflow Menu icon on the far right of the action bar as seen in the image below? My Holo theme specifies this 3 row black stack icon by default and i want something else. i can't seem to find a solution for this. I have looked at the documentation on http://developer.android.com/guide/topics/ui/menus.html but it doesn't seem to lend much help.
Thanks!
You can try something like this:
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/my_action_bTutton_overflow</item>
</style>
and in AndroidManifest.xml
<application
android:theme="#style/MyTheme" >
Define a custom style: for example, let's call it customoverflow.
In this style you set android:src to the picture you would like to use.
Now create a style with parent Theme.holo.
In this style you need to define:
<item name="android:actionOverflowButtonStyle">#style/customoverflow</item>
I just tested this and it works.
If you are using AppCompat you can achieve by following code.
res/values/themes.xml
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
<!-- Support library compatibility -->
<item name="actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
</style>
<style name="ActionButtonOverflow" parent="#style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/ic_launcher</item>
</style>
and in androidmanifest.xml
<application
android:theme="#style/MyTheme" >
I noticed that it becomes white if the theme of the app is Holo, but it is blackish when the theme is Holo.Light
However, changing the style of the action bar to inherit from Holo and the rest of the app from Holo.Light does not solve the problem, but it should point in the direction of which style you should be modifying.
What I have tried is:
<style name="AppThemeLight" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowContentOverlay">#drawable/actionbar_shadow</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/header_brown</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="android:icon">#drawable/header</item>
</style>
I have the same problem and I think this is close to a solution
Duplicate question,
Changing overflow icon in the action bar
This is my answer as below,
Change your custom overflow icon of Actionbar in styles.xml
<resources>
<!-- Base application theme. -->
<style name=“MyTheme" parent="#android:style/Theme.Holo">
<!-- Pointer to Overflow style DONT forget! -->
<item name="android:actionOverflowButtonStyle">#style/MyOverFlow</item>
</style>
<!-- Styles -->
<style name="MyOverFlow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_your_action_overflow</item>
</style>
</resources>
Put custom theme "MyTheme" in application tag of AndroidManifest.xml
<application
android:name="com.example.android.MainApp"
android:theme="#style/AppTheme">
</application>
Have fun.#.#
Shalafi's solution works with a few changes! You will need to specifiy theme.Holo as the parent for the theme but it has the downside of changing the default text color(at least in my styles).
The amended code should be:
<style name="AppThemeLight" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowContentOverlay">#drawable/actionbar_shadow</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/header_brown</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="android:icon">#drawable/header</item>
</style>
Basically Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go values/styles.xml
Shalafi's solution works with a few additions:So
add this code to both res/values-vXX/styles.xml and res/values/styles.xml and this will work like Magic!
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow"parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/your_overflow_icon</item>
</style>
also add it in AndroidManifest.xml
<application
android:theme="#style/AppTheme" >
<style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:tint">#color/colorAccent</item>
create the above theme.set tint with your color and add this theme to the toolbar.
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolBarTheme"/>