I want to define a default style for my buttons so that I don't have to type style="#style/mainButtonStyle" inside of each button manually. I have already defined the style.
<style name="mainButtonStyle" parent="android:Widget.Material.Button">
<item name="android:background">#drawable/button_default_background</item>
<item name="android:textAllCaps">true</item>
<item name="android:textStyle">bold</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
And already added an android:buttonStyle attribute in the app's theme.
themes.xml
<!-- Base application theme. -->
<style name="Theme.PlanShopping" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#AA0000</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<item name="colorSurface">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:buttonStyle">#style/mainButtonStyle</item>
</style>
The Android Manifest has android:theme attribute set up by default.
<application
android:name=".PlannerApplication"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.PlanShopping"
tools:targetApi="31">
...
</application>
So why is it not changing the default button style? The style works fine if I type it manually inside of a button. But it's not the result I wanted. How can I set it by default? I've tried to inherit from different types of buttons: android:Widget.Button, android:Widget.Holo.Button. Also, different <Button> types did not help. For now, I'm using a default <Button> component (not material or holo).
If the button is a MaterialButton you will need to specify:
<item name="materialButtonStyle">#style/mainButtonStyle</item>
Related
I have a ProgressBar, Switch, and TextInput, and I need to be able to specify a different color for each one of them.
When I do this, it changes the color of all 3 items.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#e8c4c7</item>
</style>
I'm looking for a command that only changes the color of the UI Element I want. something like:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="progressBar">#aaaaaa</item>
<item name="switch">#bbbbbb</item>
<item name="textInput">#cccccc</item>
</style>
Unfortunately, I am unable to change the style for each element directly (cause im using ReactNative). I need a solution that uses those global settings.
style.xml:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar, also for button color-->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
<!--progress bar theme-->
<item name="android:progressBarStyle">#style/myprogress</item>
<!--switch button theme-->
<item name="android:switchStyle">#style/myswith</item>
</style>
</resources>
<!--progress bar style,-->
<style name="myprogress" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:background">#color/white_color</item>
</style>
<style name="myswitch" parent="Widget.AppCompat.CompoundButton.Switch"></style>
Manifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".activity.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Sample:
Some code like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:progressBarStyle">#style/progress</item>
<item name="android:switchStyle">#style/swith</item>
<item name="android:textAppearance">#style/text</item>
</style>
<style name="progress" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:background"></item>
</style>
<style name="swith" parent="Widget.AppCompat.CompoundButton.Switch"></style>
<style name="text" parent="TextAppearance.AppCompat"></style>
I am trying to change the background color of the Popup menu in the action bar.
Everything that I try its always the same black color, that is by default.
This is what I have in my styles.xml
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/app_navbar_background</item>
<item name="colorPrimaryDark">#color/app_navbar_background</item>
<item name="colorAccent">#color/CadetBlue</item>
<item name="android:textColorSecondary">#color/black</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#color/MediumPurple</item>
</style>
And I do have the theme set in the AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Does anybody know what I could be doing wrong
Try using this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:itemBackground">#color/app_navbar_background</item>
</style>
I updated my SDK API 20 to API 22 in Eclipse.
After Updating My Sdk i Imported My Project from Other Workspace
Problem:
Actionbar App icon Not Showing in My Application.
I Already set theme Color in Themes.xml thats not Showing. it Changed as Default Black Colour.
Its Changed full structure of my App. Before Updating it works fine.
Please anyone Help me to Solve this.
manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name="com.example.Start"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">#style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">#style/Divider</item>
</style>
<!-- for Tab divider -->
<style name="Divider" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:divider">#android:color/transparent</item> //or use your transparent drawable image
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">0dp</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/easy</item>
<!-- Support library compatibility -->
<item name="background">#color/easy</item>
</style>
<style name="MyActionBarTabs" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/actionbar_tab_indicator</item>
</style>
<style name="MyTheme.ActionBar.TabText" parent="android:style/Widget.Holo.ActionBar.TabText">
<!-- This is a Black text color when selected and a WHITE color otherwise -->
<item name="android:textColor">#color/selector_tab_text</item>
</style>
</resources>
I had the same problem.
To show icon use:
getSupportActionBar().setIcon(R.drawable.ic_your_icon);
in your activity onCreate()
And for color add:
<item name="colorPrimary">#color/your_color</item>
to "CustomActionBarTheme" (not to "MyActionBar"!)
And your theme should look like:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="colorPrimary">#color/your_color</item><!--put your color here-->
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">#style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">#style/Divider</item>
</style>
And the other stuff in your theme.xml stays unchanged
It's possible to change titelbar appearence? i would make it transparent and change default settings icon with a custom image. This is how my theme is write:
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#drawable/my_bg</item>
</style>
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault">
<item name="android:textColor">#colorhere</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#colorhere</item>
</style>
and don't forget to check
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Take a look at the Android Action Bar Style Generator, it is a very useful tool for styling your Action Bar.
I want to set my application to full screen view. I got the idea to set it in an individual activity using FullScreen and NoTitlebar, but i want to set it in my Manifest XML file for the whole application not for each activity... Is this possible?
Help me... Thanks.
To set your App or any individual activity display in Full Screen mode, insert the code
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
in AndroidManifest.xml, under application or activity tab.
Another way: add windowNoTitle and windowFullscreen attributes directly to the theme (you can find styles.xml file in res/values/ directory):
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
in the manifest file, in application specify your theme
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
If your Manifest.xml has the default android:theme="#style/AppTheme"
Go to res/values/styles.xml and change
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
And the ActionBar is disappeared!
In AndroidManifest.xml, set android:theme="#android:style/Theme.NoTitleBar.Fullscreen"in application tag.
Individual activities can override the default by setting their own theme attributes.
Try using these theme: Theme.AppCompat.Light.NoActionBar
Mi Style XML file looks like these and works just fine:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
This seems to be an old questions with some old answers. We found that the easiest way to do this in a new project is to edit the res/values/themes/themes.xml file.
Actionbar:
Change the parent attribute in the style element to "Theme.MaterialComponents.DayNight.NoActionBar" like this
<style name="Theme.WeatherDisplay" parent="Theme.MaterialComponents.DayNight.NoActionBar">
Status bar:
Add the following line under the style element
<item name="android:windowFullscreen">true</item>
Here is the resulting themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.NameOfApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
</style>