My app uses a custom titlebar created as a layout and is implemented using this format:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);
super.onCreate(savedInstanceState);
Now it did not work using the regular theme android:Theme.Light, neither did android:Theme.Light.NoTitleBar, they both resulted in a fatal exception when setContentView was called. So I created a custom style which looks like this:
<style name="MyWindowTitleBackground">
<item name="android:background">#000000</item>
</style>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowTitleBackgroundStyle">#style/MyWindowTitleBackground</item>
<item name="android:windowActionBar">false</item>
<item name ="android:windowTitleSize">35dip</item>
</style>
However, every time the app is started there is a small delay in between the start and display of the actual layout with the custom titlebar, in this delay the default titlebar is shown with the appname in it. After about a second, when the Oncreate finishes, the custom title is loaded and shown.
Is there any way to fix this? What am I doing wrong?
Try putting
super.onCreate(savedInstanceState);
before the other lines and see if that works.
and putting
setContentView(R.layout.my_layout);
last. I seemed to remember my app crashing because I had it in the wrong order.
Related
hello i have to remove actionBar into an activity, this is my style:
<style name="AppTemaGiornoFullScreen" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
this work very well into android 4x, but into an 2x emulator actionBar is always visible.. why?
You can hide it programatically from the Activity itself using this line of code in your
OnCreate method after setContentView line
getActionBar().hide();
If you are using tabs activity, use this:
getParent().getActionBar().hide();
This is a similar question .. Link
If you are asking about hiding the TitleBar programatically..Add the following lines on your onCreate before setContentView line
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
This is a similar question .. Link
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.
How to achieve this? It seems very simple, but actually it's not easy to do it in acceptable way. I tried this:
1) in AndroidManifest I set activity theme to Theme.NoTitleBar. However, in my Activity then getActionBar() method returns null => UNUSABLE
2) I hide title programatically in my activity by calling:
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
and it helped, but there's a little delay, so I can see title bar maybe quarter of second after activity launch, then it disappears. It looks really lame.
Are there other options?
Apply a custom theme to your Activity, something like:
<style name="TestTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/TestActionBar</item>
</style>
<style name="TestActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:displayOptions"></item>
</style>
This will show the action bar with the logo, but no title.
Have u try bellow code :-
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.ur activityxml);
or also try below one
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activityxml);
I'm using a custom title bar in my app and it all works fine except that when the app starts up, the original (standard) android title bar is shown for a brief time before it is replaced by my custom title bar.
This is not a problem when the app is already loaded in memory because the 'delay' is not apparent but if the app is not already in memory, it is very obvious.
There's nothing special about the code :
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
I thought about changing the style to have no window title and just include my custom title in the top of the layout but that doesn't seem right.
Thanks for any pointers.
Thomas Devaux has posted a smart solution. It worked in my app
Change the windowTitleBackgroundStyle to use color “#android:color/transparent”.
Also create a style for the text “android:windowTitleStyle” and set its “android:textColor” >to transparent as well.
For completeness to Lluis' answer, here's the full code you need to hide the default-title before the custom-title is initiated:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleStyle">
<item name="android:textColor">#android:color/transparent</item>
</style>
<style name="CustomTheme" parent="#android:style/Theme.Holo">
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleBackgroundStyle">#android:color/transparent</item>
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleStyle">#style/CustomWindowTitleStyle</item>
</style>
</resources>
add a splash screen activity before the main activity loads, should have enough time for the next one to load properly
Are you able to use an app theme to set a custom title globally for your app? See here for a pretty good example. I had a similar problem and i seem to remember going this route fixed it.
Currently, I'm using this to show my application background as phone wallpaper.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER,
WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
But for some reason when I start my application by pressing the icon. It just shows the activity screen with the icons on the home screen. I didn't use dialog but it looks like a dialog because layout is just set that way. So I just want to show the wallpaper whenever this activity is running. But it only shows the wallpaper only after the next event occurs such as switching to different activity. I already put that code on onCreate() and whenever I do setContentView()..... Is there way to do such thing or there is just no way?
For users of AppCompat, just use the following in your styles.xml, no need for code:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
After long search and trial and error. I've found the solution to what I wanted. It was just creating separate themes.xml file and just tweak the Theme.Dialog which is already defined in default android themes.xml. All I did was change the Animation part. Originally in android themes.xml the line looks like this.
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
but since modifying in android themes.xml doesn't take the effect. I just created my own themes.xml as I said above and just set parent as android:Theme.Dialog. And added a line like this.
<item name="android:windowAnimationStyle">#android:style/Animation</item>
Thanks for the help and I hope this solution helps others.
Use following code -
rl = (RelativeLayout)findViewById(R.id.someid);
//relative layout is my root node in main.xml (yours may be linearlayout)
WallpaperManager wm = WallpaperManager.getInstance(this);
Drawable d = wm.peekDrawable();
rl.setBackgroundDrawable(d);// You can also use rl.setBackgroundDrawable(getWallpaper);