How do I change the theme of my app in android studio? - android

I change the theme from the design section from the dropdown menu like material dark, holo, etc. But when I run the app on the device the app doesn't show any changes, hence I understood the code does not change so what is the code I need to write in style section to change the theme?

AndroidStudio only shows how it will look if you will apply that theme in your app programmatically by yourself.

In res/values/styles.xml you can add following code to change theme:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
<item name="android:colorControlActivated">#color/colorPrimaryDark</item>
<item name="android:colorControlHighlight">#color/colorPrimary</item>
<item name="android:colorControlNormal">#color/colorPrimary</item>
<item name="android:windowBackground">#color/colorBackground</item>
</style>
</resources>
you can change theme by modifying parent attribute

You should edit the application manifest and add
android:theme attribute to either application or activity tag with the theme you want.

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
if(mode.equals("dark")){
setTheme(android.R.style.DarkTheme);
}else if(mode.equals("light")){
setTheme(android.R.style.LightTheme);
}else{
setTheme(android.R.style.AppTheme);
}
}

Related

Customize Android TimePicker to use Spinner in .net Maui

I want to customize my TimePicker in .Net Maui to use the Spinner mode on Android(possible modes in android) and not the clock mode. Is this possible with Maui Handlers?
I was looking for something like this
#if ANDROID
Microsoft.Maui.Handlers.TimePickerHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
??? handler.PlatformView.TimePickerMode ???;
});
#endif
Or can I style it somehow?
The TimePicker's default mode is clock, and the attribute can just be set in the android layout xml or when it be created by calling the construction method. So you can't set it with the Muai Handler.
But you can use the android style to change the TimePicker's default mode.
Create the style.xml under the /Platform/Android/Resource/values folder:
<resources>
<style name="Spinner" parent="android:Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">spinner</item>
</style>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:timePickerStyle">#style/Spinner</item>
</style>
<style name="Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#android:color/holo_blue_dark</item>
<item name="android:windowSplashScreenIconBackgroundColor">#000000</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/logo</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
</resources>
In the AndroidManifest.xml:
<application android:allowBackup="true" android:theme="#style/Splash" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true"></application>
Add the package named AndroidX.Core.SplashScreen in your android part.
Delete the (Theme="#style/Maui.SplashTheme") in the MainActivity and add the following code in the its OnCreate method's first line:
AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(this);
I have done a sample to test. The splash screen doesn't work when I set the item in the Maui.SplashTheme. So I declare another Theme for the application. But when I use the other control, the splash screen doesn't work.
So you can try to use the solution above or Just use the following code and set AppTheme as the MainActivity's theme. And then create a splash screen follwing the xamarin.android splash screen.
<resources>
<style name="Spinner" parent="android:Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">spinner</item>
</style>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:timePickerStyle">#style/Spinner</item>
</style>
</resources>

i am unable to apply "Theme.AppCompat.NoTitleBar" and "colorPrimaryDark" status bar color property at the same time

I want to hide the action bar throughout the application and also want to set the status bar color? in Appcelerator titanium.
Please follow the official guide at https://wiki.appcelerator.org/display/guides2/Android+Action+Bar
You can either hide it in code win.activity.actionBar.hide(); in the open event and use a normal style in the theme xml or you set your parent in the theme to
<style name="Theme.MyTheme" parent="Theme.AppCompat.NoTitleBar">.
Statusbar color is a theme item:
<item name="android:statusBarColor">#ff0000</item>. You can add into your theme.
Here is a style I'm using as an example:
<style name="Theme.MyTheme" parent="Theme.AppCompat.NoTitleBar">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="android:statusBarColor">#00d59e</item>
<item name="colorAccent">#ff225c</item>
<item name="android:textColorHint">#999999</item>
</style>
using
"Window" : {
theme: "Theme.MyTheme",
barColor: "#ff225c"
}
I kept my custom theme file inside
App->Platform->Android->res->values->mytheme.xml
and my xml file looks like below and it works fine for me..
<resources>
<style name="Theme.MyTheme" parent="Theme.AppCompat.NoTitleBar.Fullscreen">
<item name="buttonStyle">#style/MyButton</item>
</style>
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
</resources>
and in tiapp.xml file inside maifest
<application android:theme="#style/Theme.MyTheme"/>
Try this code.May be it will help you. -
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.color_name));
}

Actionbar Sherlock title shows for a sec at first run

As i mentioned in title of question I want to completely remove title from actionbar but at first run (when I run it from eclipse) title shows for a while and it's not what I want
in the onCreate method I've add this 2 line of code and its work but LATE!!
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayShowTitleEnabled(false);
may this 2 pics help u understand me
Set your theme to 'no action bar' in your manifest, then apply your normal theme in code after set contentview!
android:theme="#style/Theme.Sherlock.Light.NoActionBar"
and then.
this.setTheme(R.style.myTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
While your code hides actionBar Title, the title will still be displayed while your activity is loading and before you remove the title in your code.
I think a better solution if you want to remove title from actionbar in all of your activities from the start is to do it by setting a theme and override the actionbar style.
To do this you have to create a style in your styles.xml and use this as your application theme e.g.
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/AppTheme.ActionBarStyle.TitleTextStyle</item>
<item name="titleTextStyle">#style/AppTheme.ActionBarStyle.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBarStyle.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textSize">0dp</item>
<item name="textSize">0sp</item>
<item name="android:textColor">#00000000</item>
<item name="textColor">#00000000</item>
</style>
or another example:
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/AppTheme.ActionBarStyle</item>
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions" tools:ignore="NewApi">useLogo|showHome</item>
<item name="displayOptions">useLogo|showHome</item>
</style>
These Code samples were taken from some of my projects where i use actionbarsherlock so you may have to edit it according to your needs.
Hope it helps.

Android custom theme

Hello I'm making a custom theme for my app. I want to have a custom ActionBar and background for the rest of the app (below the ActionBar). I'm wondering how to do the background. Right now I have:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/dActionBar</item>
</style>
<style name="dActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#4C721D</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Would I just have to do <item name-"android:background"></item> in MyTheme or would I have to create another style? After I create this do I need to put it in the res/styles folder? Also what are the API restrictions on this, if any?
Don't forget to apply your theme to your application in your AndroidManifest.xml.
<application android:theme="#style/CustomActivityTheme" ... />
You can find all the information about styling the Actionbar here.
To style your ActionBar with a nice Holo-look, try this website
Hope this helps!
Try to use below code in your Style.xml file
<resources>
<style name="Theme.Sample" parent="Theme.AppCompat">
<item name="android:colorBackground">#color/primary_material_dark</item>
<item name="actionBarTheme">#color/colorGray</item>
</style>
</resources>
Just need to use android:colorBackground as a name of item to define the background color like as below:
<item name="android:colorBackground">#color/primary_material_dark</item>
Hope you get your answer,Thanks.

Custom theme and sherlockActionBar

I am doing a personal theme to use holo widget in 2.3 android.
I did this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppThemes" parent="#style/Theme.Sherlock">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:checkboxStyle">#style/CheckBoxAppTheme</item>
<item name="android:radioButtonStyle">#style/RadioButtonAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:spinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme.DropDown</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemAppTheme</item>
</style>
</resources>
the problem is that widgets don't take the correct style but take the default style. I tried to force assign the #style/EditTextAppTheme at an edittext and it worked.. so the problem is that the theme don't apply.
any idea?
update: the theme apply and work good..the solo problem is some edittext inside a dialog that show with the standard theme
To get the holo theme style in an App for API 10 and below, you can use HoloEverywhere. It's well integrated with ActionBarSherlock. ActionBarSherlock is included as a subproject. https://github.com/ChristopheVersieux/HoloEverywhere
If you want to use a customized Theme you have to set these style attributes in your Application theme. Then apply this theme to the whole App or to a single Activity by defining it in the manifest or setting it programmaticaly in the onCreate() method.
For example(for ABS):
<style name="Theme.myStyle" parent="Theme.Sherlock">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:checkboxStyle">#style/CheckBoxAppTheme</item>
<item name="android:radioButtonStyle">#style/RadioButtonAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:spinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme.DropDown</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemAppTheme</item>
</style>
And then set this theme to your Application or your Activity in the Manifest with:
android:theme="#style/Theme.myStyle"
or programmatically:
setTheme(R.style.Theme.myStyle);

Categories

Resources