I'm trying to customize my Android theme, but nothing seems to work.
Activity:
public class MainActivity extends AppCompatActivity {
...
}
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Delete" parent="Theme.MaterialComponents.Light">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryVariant">#color/primary</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/primary</item>
<item name="colorSecondaryVariant">#color/primary</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="materialButtonStyle">#style/Widget.App.Button</item>
</style>
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">#style/ThemeOverlay.Button</item>
<item name="colorPrimary">#color/primary</item>
</style>
<style name="ThemeOverlay.Button" parent="" >
<!-- For filled buttons, your theme's colorPrimary provides the default background color of the component-->
<item name="colorPrimary">#color/primary</item>
</style>
</resources>
In layout I'm using Material Design Components for example
<com.google.android.material.button.MaterialButton
android:id="#+id/button_home_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/home_all"
app:layout_constraintStart_toStartOf="parent"/>
but the default purple_200 background color is applied to the button. Can you help me a bit? I read that there I should use Activity instead of AppCompatActivity but I can't change it as my activity is a bottom navigation activity I can't find support for onSupportNavigateUp or other realated stuff
EDIT
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="licenta.allbank">
<application
android:requestLegacyExternalStorage="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AllBank"
android:usesCleartextTraffic="true">
<activity
android:name=".activity.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="callback"
android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>
To use a MaterialButton you have to use a Theme.MaterialComponents.* theme in your app.
Then you can define the materialButtonStyle attribute.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
....
<item name="materialButtonStyle">#style/Widget.App.Button</item>
</style>
In this way you can customize the theme of all the buttons in your app.
To override the default background color you can use the materialThemeOverlay attribute:
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">#style/ThemeOverlay.Button</item>
</style>
<style name="ThemeOverlay.Button" parent="" >
<!-- For filled buttons, your theme's colorPrimary provides the default background color of the component-->
<item name="colorPrimary">#color/my_color</item>
</style>
Otherwise you can use the backgroundTint attribute in your custom style:
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<!-- Background color -->
<item name="backgroundTint">#color/buttonBackgroundSelector</item>
</style>
Figured it out. If you're testing on your phisical device and it is set on dark mode, you should make the changes in your values-night/themes.xml file, otherwise, working on your values/themes.xml should be enough
Related
I have removed the action bar for a specific activity and it is working perfectly and the action bar is removed when I run the app on Emulator/Device but the problem is that it is still showing in the preview. Due which It affects my design.
Here is my style file where I set the noAction bar:
<resources>
<!-- Base application theme. -->
<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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!-- Text Styles -->
<style name="textStyle">
<item name="android:textColor">#color/theme_color</item>
<item name="android:textSize">16sp</item>
</style>
<style name="textStyle.tagline">
<item name="android:textAllCaps">true</item>
<item name="android:textSize">46sp</item>
</style>
<!-- Button Styles -->
<style name="button_transparent">
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/theme_color</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="button_blue">
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/white</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
I have also applied that style on activities as shown here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eapple.karumber">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Splash_Screen" android:theme="#style/AppTheme.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".protips_activity" android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
But is still showing in the preview as shown here:
Android Studio preview
Fastest solution:
Open your activity's XML.
Switch to the design tab.
On the upper part of the design tab click on AppTheme.
Choose your new theme (the one with no action bar).
However
Adding this line to the activity XML root view should automatically reference to the same activity theme set in AndroidManifest
tools:context=".YourActivityName"
If this is only on the preview u can change the theme with an option on the top of the view. Just select you theme with NoActionBar
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 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
No matter what I do, the action bar text is black, I need to change it to white.
I have tried this
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:colorPrimary">#color/primary_color</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Medium">
<item name="android:textColorPrimary">#android:color/white</item>
</style>
and this
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView abTitle = (TextView) findViewById(titleId);
abTitle.setTextColor(colorId);
the second answer from here How to change action bar title color in code, just crashes the program, the first answer doesn't work. Please help??
Copy the style.xml inside a new directory called values-v21 and then simply replace with this:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<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>
</style>
For more information see Maintaining Compatibility
This must work: Add it to res/values/styles.xml
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:colorPrimary">#color/primary_color</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/Textstyle</item>
</style>
<style name="Textstyle" parent="#android:style/Widget.TextView">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
And change your AndroidManifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"> // <--------- Here -------->
<activity
android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I have following style definitions in my res/values/style.xml file:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:textColor">#fff</item>
<item name="android:textSize">12sp</item>
</style>
<style name="MainActivity" parent="AppTheme">
<item name="android:textColor">#f0f</item>
<item name="android:background">#color/black</item>
</style>
And following code in manifest file:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:theme="#style/MainActivity"
android:name="com.example.mygateway.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>
I expect that textColor #f0f will be applied to MainActivity activity, but it isn't.
Neither textColor no other items i tried are applied.
Actually the only AppTheme is applied to the activity and the whole application.
I'am a beginner in android development. What I do wrong?
Please help.
Thanks!
As official docs state:
"If you want to inherit from styles that you've defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period. For example, to create a new style that inherits the CodeFont style defined above, but make the color red, you can author the new style like this:"
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textColor">#fff</item>
<item name="android:textSize">12sp</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:textColor">#f0f</item>
<item name="android:background">#color/black</item>
</style>
and
<activity android:theme="#style/AppTheme.MainActivity"
...>
...
</activity>`