Android Studio: Application themes aren't correctly applied - android

I'm having trouble modifying the default application theme in Android Studio.
As a really simple test I just want to remove the default ActionBar in a default starting project. I do this by setting a "NoActionBar" theme in the preview pane. When I run the application however, no changes are applied.
Is modifying the theme of an application in AndroidStudio through the preview pane the correct way of applying said theme to your application?
Are there any additional steps that need to be taken to apply the changes and if so, what are they? (if thats the case, its not exactly intuitive that changes in the preview pane don't show up in your actual application)

First, have a look at this answer https://stackoverflow.com/a/29001288/4188219
So, the selected theme for preview is just a way to let you know what effect the selected theme will be, but if you want use some theme to your app when run on device, you must define it in xml or code. That is to say, the preview theme does not affect the actual theme of app.

If you want to remove the action bar then in your manifest file in activity tag enter <android:theme="#android:style/Theme.NoTitleBar">
and also you can start your activity like public class yourclass extends Activity instead of extends ActionBarActivity
Hope it helps ...

you should change theme in Manifest or activity class, something like this:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"

The easiest way is to simply define the theme the entire application uses, by mentioning it in the manifest file, under the application tag as below, (Since I wanted a dark actionbar so I mentioned that)
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.DayNight.DarkActionBar">

Related

Android: Must a Fragment's Theme be the Same as the Main Activity/App Manifest?

I made a new Fragment and tried to set it's theme to AppCompat.NoActionBar using Android Studio's Design tool. The problem is, once I selected it, the theme did not change and stayed on the default app theme.
After Manually Setting the theme on the Android Manifest to Theme.AppCompat.NoActionBar the Fragment then accepted the Theme Change.
I want to ask the following:
Can Fragments have different Themes independent from the App Manifest or Main Activity? (Since I assume setting the Theme in the App Manifest changes it for all Activities and Fragments).
I was looking for a way to just set the Fragment's theme to AppCompat.NoActionBar but didn't get a way to do it without setting it in the App Manifest.
This is my First Question on StackOverFlow, hope it's a valid question since I couldn't find the answer online. :)

Theme in android

I´m noob in the android programming area, and I have a big problem with changing the theme in eclipse!! The app runs nice with the predetermined theme, when I change it i did this:
1) go to the manifest > Application > select "Browse" > this theme: #android:style/Theme.Black.NoTitleBar.Fullscreen (did apear at the code)
2) activity_Main > I selected the same theme but didn´t apear at the code.
thats it! and when i run it the AVD says: "The application Bola de cristal (Process com.RMapps.boladecristal) has stopped unexpectedly. Please try again"
I dont know what to do! please someone has an idea? thanks in advanced!!
Excuse my english, its not my first language.
Take a look at the actual XML of the manifest. You should see your theme under application:
<application
android:theme="android:style/Theme.Black.NoTitleBar.Fullscreen
This will apply the themem to all activities that don't explicitly override it.
In Eclipse, when viewing the activity designer, you can select themes from a dropdown and you will see the change take place in front of you but this will not actually save and compile for you. So when you run your app, you will be a bit confused. You need to explicitly declare the theme for an activity under that activity def in the manifest, just like you did for the application as a whole.
<activity
android:theme="android:style/Theme.Black.NoTitleBar.Fullscreen
But again, you don't need to do this if you want to use the theme that you set at the application level.
If your app is still crashing then you have another problem going on. Perhaps the theme you are selecting isn't actually present or maybe you have another bug you didn't realize you introduced during the time of adjusting the theme

android - how to loop through all activities?

In my android app, i can change the theme, but to see the change I have to exit the app and open it again.
This is how I change the theme.
ThemeSetterActivity.setStyle(signup.this);
which happens on the create event.
But is there some code like this (below) that I can run, and will change the theme for all the activities.
foreach (activity act in app) {
ThemeSetterActivity.setStyle(act.context);
}
thanks
As far as I know you can't do it that way.
What I do is have each activity keep track of what theme it is currently using.
Then in each activities on resume just check if the current theme is still what it should be, if not restart the activity.
An easy way to get that application wide is to just have your base activity class implement that behavior, and then have all activities extend that.
Apply a theme to an Activity or application
To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the tag to include the android:theme attribute with the style name. For example:
<application android:theme="#style/CustomTheme">
If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the tag instead.
Just as Android provides other built-in resources, there are many pre-defined themes that you can use, to avoid writing them yourself. For example, you can use the Dialog theme and make your Activity appear like a dialog box:
<activity android:theme="#android:style/Theme.Dialog">
use static field and store your theme id;
and in onCreate method use :
yourActivityObj.setTheme(R.style.AppTheme);
maybe id work;

Android: UI old interface

For some Activity I'm using #Theme/Dialog, but this appears like old UI 2.3.
If I set the Theme of the Activity in the Manifest as Holo/Dialog, then this work fine, but of course this will not work with older devices.
How to force Holo Theme when available?
I tried with a custom MyTheme, but all the activity that have #android:style/Theme.Dialog, continue to appear like old theme.
My activity look like below:
<activity
android:name=".audio.TempoManager"
android:label="Tempo Manager"
android:theme="#android:style/Theme.Dialog" />
if I change it to #android:style/Theme.Holo.Dialog then on old device the activities will not be open as dialog but as simple activity.
refer to this blog post. it answers your question: holo-everywhere
mainly:
1. you write a theme.xml file defining a MyTheme in res/values/ for all pre-3.0 android versions.
2. write a themes.xml file defining the MyTheme in res/values-v11/ for 3.0+ android versions.
3. in the AndroidManifest.xml define the application theme to be MyTheme.
the first theme inherits from #android:style/Theme.
the second theme inherits from #android:style/Theme.Holo.
If ICS is available on the device it will default to Holo,
If you want to create for instance the ICS font universally on all devices you will need to provide the ttf font file asset and use it in a custom textview and/or buttons etc..

Implement change black/light theme feature in Android app

I want to have a "change theme" feature in my app. If I call setTheme() in onCreate(), there is one problem.
The moment after I launch my app, a plain white background appears for a second (because I have set light theme in the manifest). After that, the complete layout of my Activity is displayed - it is either with white or black background, according to user's theme preference.
Is there any way I can change whether white or black background appears after launch?
Make sure you call setTheme() in onCreate() BEFORE calling setContentView(). Then if you want to dynamically change the theme again later, you should simply restart your activity.
If you are adding a theme to the entire program than you could start by doing:
In your manifest you add to your application tag that you are using a theme.
<application android:theme="#style/mythemename">
Then look at Theme XML to make sure that you have what you need declared in the appropriate places.
If it is just for a particular action you could add the activity tag
<activity android:theme="#android:style/Theme.propertyname">
You can also, if you want your theme to just change the background color, follow the same pattern with either the activity or application tag (what ever one you are using) and set the item name "colorbackground" to what you want.
You can also use Theme XML and remake what you want in your current theme and call that your custom theme using the method above.
I hope this helps and if not please let me know so I might be able to help better in the future.
Another way would be to have a kind of splash screen which will check for a preference variable for example and then decide whether to use the light or the dark theme. This way you could also use XML layouts.
EDIT: Yet another way is to have the all the layout defining stuff in the onCreate() method and then just trigger the onStart() method when ready.

Categories

Resources