In my application, I'm using ActionBarSherlock library. Also I'm using a custom title bar.
Here goes my onCreate:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main_tab);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
And in my styles.mxl
<style name="MyTheme" parent="Theme.Sherlock">
<item name="android:background">#ff888888</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">#style/windowTitleBackgroundStyle</item>
</style>
<style name="windowTitleBackgroundStyle">
<item name="android:background">#00688B</item>
</style>
In Manifest file i am using MyTheme for the activity.
android:theme="#style/MyTheme"
This code properly works with lower android version (I have tested with GB2.3.5). But when i tested with ICS, its crashing with the Below error:
"You cannot combine custom title with other title features"
I went thoroughly in StackOVerflow discussions, but unable to resolve the issue.
solutions tried:
1) false
2) there is no values-v11 folder
I received the same exception.
Here is what I found: In newer versions of Android, the framework will use the Window.FEATURE_ACTION_BAR feature whenever the Holo theme is selected. The framework throws the exception whenever an app calls setFeatureInt(Window.FEATURE_CUSTOM_TITLE) and FEATURE_ACTION_BAR has already been set.
In my case, the styles.xml file in the values-v11 folder was redefining my theme to inherit from android:Theme.Holo. When I attempted to run my app on a Android 3.0 or above - it crashed because Holo uses the ActionBar by default. The fix was simple. Turn the ActionBar off when using Holo. Here is the revised values-v11\styles.xml changes:
<style name="AppBaseTheme" parent="android:Theme.Holo.NoActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
I had the same problem and solved it:
THE ROOT CAUSE:
In the Manifest, I copy pasted this tag by mistake from my splash screen into my activity: #android:style/Theme.NoTitleBar
The fatal exception occured when I also requested a FEATURE_CUSTOM_TITLE on my activity, causing the conflict.
SOLUTION:
To fix it, I checked these 3 things:
1)OnCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_login);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_titlebar);
}
2)INSIDE your manifest.xml:
Make sure a line such as these ONLY appears in a splash screen if you have one:
android:theme="#android:style/Theme.NoTitleBar
REMOVE that line from any other activity if you want a custom Bar.
In the application tag , my only theme tag is this one:
android:theme="#style/AppTheme"
In the activity tag, I have no theme tag.
3) Go to your activity's XML layout, and view it in GRAPHIC LAYOUT mode.
Maye sure your that the Theme says AppTheme (its the the you put on the manifest)
Mine said "No Title", so this was causing the problem.
Related
I have a LoginActivity where I use an AppCompat theme like this:
<activity
android:name=".LoginActivity"
android:theme="#style/Theme.AppCompat.Light.Dialog"
android:label="Login" />
I am aware that as of this post Google has not yet added Material Themes in AppCompat library for DIALOGS, so I assumed it will fall back on Holo. Instead, this is what I get:
Keep in mind, I am not using the AppCompat toolBar. In the Activity, I am not even making a reference to the ActionBar. What you see above is default behavior, yet I cannot figure out where it is coming from. Is this a bug perhaps?
(Also, the EditText fields are not being colored with the Primary color for the app.)
Note: see my final edit for possibly the best solution
For what it's worth, I do think this is a bug. However, a valid workaround that I discovered is to use #style/Base.Theme.AppCompat.Light.Dialog.FixedSize. Based on your screenshot I think this will work for you as well. However, I have not tested palette coloring yet.
From what I can tell in my testing, this extends the gray border while still allowing you to use AppCompat and v21.
Edit: one side-effect is it now appears that all dialog activities are the same size, which may not work for you. Also, I haven't figured out how to remove the title - requestWindowFeature and supportRequestWindowFeature with Window.FEATURE_NO_TITLE seems to be causing
java.lang.RuntimeException: Unable to start activity ComponentInfo{myclass}:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
even though I've tried it before and after super.onCreate and definitely before setContentView
Edit#2: Removing the title via XML theming works, and since you have no title there is no bizarre gray box to worry about, which means you can drop the FixedSize setting and the dialog will wrap it's content like it did in earlier versions.
<style name="MyActivityDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Edit #3: You can also just simply remove the gray background - this may be the best solution because it does not require the Base. prefix:
<style name="MyTitledActivityDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleBackgroundStyle">#android:color/transparent</item>
<item name="windowActionBar">false</item>
</style>
I am setting theme for each activity seperately in the corresponding activity.java file.
setTheme(android.R.style.Theme_Holo_Light);
Can i set the theme globally in the manifest file and then override it to change action bar background color etc.
In AndroidManifest.xml
<application
android:theme="#style/MyAppTheme">
In styles.xml
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
</style>
But it crashes.Why?
as per my guessing it is happening
cause your using theme which is not supporting to actionbar and your calling actionbar related code in such activity i mean your app may be crashing in that activity where you write actionbar related code but unfortunately the theme for that activity is not actionbar related theme thats why may be it comes
use actionbar related theme in that activity using
android:theme="#style/actionbar supported theme"
line in manifest against that activity
How to hide the action bar and get full screen with Theme.AppCompat.Light on Android 2.x? I had tried following code on styles.xml:
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
It doens't work. How to solve without use java code?
That configuration works. Just make sure you are adding the correct Theme from the correct styles.xml (not from values-vXX folder styles) file to your Activity in manifest.xml file.
Also make sure your Activity does not extend ActionBarActivity, but FragmentActivity, as you do not want the ActionBar to show.
I've got an application that draws a custom title bar using the following style for the application theme:
<style name="App_Theme" parent="android:Theme">
<item name="android:windowTitleSize">30dip</item>
<item name="android:windowTitleBackgroundStyle">#style/App_TitleBackground</item>
</style>
This does not give me the holo theme. So I set the to parent="#android:style/Theme.Holo". This crashes the application with the following error:
E/AndroidRuntime(2048): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
Is it disallowed to use custom title bar using:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
Or am I missing something here?
PS:
The code works perfectly fine with the parent set to "Android:Theme".
I'm using API Level 14
Let your activity use a theme with following attribute:
<item name="android:windowActionBar">false</item>
mido is correct
<item name="android:windowActionBar">false</item>
is the solution when using #android:style/Theme.Holo (default for ICS).
One observation, if you use #android:style/Theme.Holo.NoActionBar change it back to the default #android:style/Theme.Holo.
Mostly for the benefit of future visitors, one cannot use Window.FEATURE_CUSTOM_TITLE with Holo themes. Setting android:windowActionBar is not what I wanted, since I wanted a title bar, although a customized one.
My workaround, was to requestWindowFeature(Window.FEATURE_NO_TITLE) and add another layout that looked like a titlebar in my activity. That way, I get the best of both worlds.
I've got a custom layout I want to use as the titlebar of my android app. The technique found (linked at the bottom) works, but the system titlebar is displayed before onCreate() is called. Obviously that looks pretty jarring, as for a moment the system titlebar is shown, then my custom titlebar is shown:
// styles.xml
<resources>
<style name="MyTheme">
<item name="android:windowTitleSize">40dip</item>
</style>
</resources>
// One of my activities, MyTheme is applied to it in the manifest.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_activity);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);
}
I could always hide the system titlebar and display my own in-line perhaps with each and every layout, but, that's not very friendly.
Thanks
http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/
I think it's a framework limitation. I had the same problem in some of my applications and the ultimate solution was for me to tell the framework I didn't want a title bar at all and then create my own in my layouts. The include directive made it bearable for me, e.g.:
<include layout="#layout/title" />
When I used requestWindowFeature(Window.FEATURE_NO_TITLE) in my activities, I would have the same issue, I'd see the system title bar briefly while the activity was being build when it first loaded.
When I switched to using a theme to tell the framework I didn't want a title, the problem went away and I now see my own title directly on first load. The styling is easy for that:
<style name="FliqTheme" parent="#android:Theme.Black">
<item name="android:windowNoTitle">true</item>
</style>
I know this doesn't apply to your issue with the custom title, but like ptc mentioned, if you move your custom title into style/theme definitions (which you do by overriding the system title styles in your theme), I think you'll be on the right track.
The same problem happened to me today when I was trying to custom the title. I solved it by set the android:theme to android:style/Theme.NoTitleBar in the AndroidManifest.xml, and call setTheme() to the actual theme I want in my activity's onCreate callback function.
Try creating a custom theme style in XML and then set your activity's theme attribute in the AndroidManifest.xml file.
http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme
The method through setting android:theme does not work for me, I have made it by adding the following code in onCreate() of my Activity subclass:
getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);