Removing Title Bar in Android 2.3 (Gingerbread) causes problem with SurfaceView - android

Anyone experiencing a problem with their app in Gingerbread? -- if you use
requestWindowFeature(Window.FEATURE_NO_TITLE);
And you switch to another window, when you come back it changes the dimensions of the surfaceview.
For now, I've put the titlebar back in to work around this issue.
Thanks for any help
Mark

Yes, we too have experienced this after updating to Android 2.3.4. To fix it in our apps we eliminated the requestWindowFeature(Window.FEATURE_NO_TITLE); in our apps and then utilized a styles.xml, saved in the project's values folder with the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="#android:style/Theme.Translucent.NoTitleBar.Fullscreen">"
<item name="android:windowBackground">#color/background</item>
</style>
Here a colors.xml will be utilized to set the #color/background, which is also saved in the project's value folder with the following:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name ="background">#000000</color>
</resources>
Then in the manifest file we utilized:
<application android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#style/Theme.Transparent"
>
to apply the theme to the application as a whole. Perhaps others will have better suggestions and also maybe a reason for why this occurs in Gingerbread as in Froyo the requestWindowFeature(Window.FEATURE_NO_TITLE); worked well with SurfaceViews.

Related

Unity android "freezes" with splash image

I have added a custom theme with background image to serve as "splash" image to make the app look nicer while unity player is loading.
That's the theme definition I have
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Test" parent="#android:style/Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#drawable/launchimage</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
Now, when I refer to this theme in AndroidManifest.xml like:
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="#style/Theme.Test" ... ></activity>
the game just "freezes" – it's hard to tell in fact, because it just displays the splash image and ... that's it. Logcat doesn't show any warnings/errors either.
Removing the theme OR changing android:windowBackground property to a solid color make the game work, but window background appears black until the game is launched.
What is the correct way to set activity background to make Unity happy?
When your image is too large this issue happen. change your image with smaller and set centerCrop attribute may fixed this issue. (usually this show skip frame in your log)
Also if you use Android studio 2.0 there is newly issue with that you can find it here.

changing text color globally with new style

EDIT: My line in AndroidManifest was wrong. It should have been
android:theme="#style/CustomTheme"
Now all the text color has changed. Not the button color but I am on my way. Thanks for the help.
This must be an easy answer but I keep getting errors. I am, as far as I can tell, following the Android documentation HERE but it doesn't work. I have read many stactoverflow threads on this issue and trying to follow what seemed like the best one. The goal is to change the text color globally in an already complete project.
This is in res/values/styles.xml
<resources>
<style name="style_name" parent="#android:style/Theme.Black">
<item name="android:textColor">#00FF00</item>
</style>
</resources>
I reference it in AndoridMinafest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/style_name"
>
What I am trying to do is keep the basic style of Theme.Black but change the text color.
What am I doing wrong? The line android:theme="#android:style/style_name" in AndroidManifest generates an error which then errors out every class.
I was close, just a typo but as I was unable to find an answer to this on the web and found lots of people asking I thought I would document exactly what ended up working. This did not work for the cases where I had hard coded a color but I would not expect that to happen. This did change all the default text colors.
AndroidManifest was modified like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
>
And the file res/values/styles.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme.Black">
<item name="android:textColor">#ffff00</item>
</style>
</resources>
And this works. All the text is yellow -- except the text defined as
android:textColor="#android:color/white"
And that is another story. I will have to edit each instance to change that.

Missing styles. Is the correct theme chosen for this layout?

Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find style mapViewStyle in current theme.
I tried every solutions available to solve this problem but nothing seems to work. I have included library in the manifest file. I even created style is styles.xml, I have chosen Google Apis build target as well.
Can somebody please give me a solution?
here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="#style/AppTheme"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="#+id/themap"
style="#style/mapViewStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="here i have my key"
android:clickable="true"
android:enabled="true" />
</RelativeLayout>
Here is my manifest snippet:
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Second" />
<activity android:name=".Third" android:theme="#android:style/Theme.Black"/>
</application>
here is my style.xml file
<resources>
<style name="mapViewStyle" parent="#android:style/Theme.Black">
</style>
</resources>
For Android Studio (or IntelliJ IDEA),
If everything looks OK in your project and you're still receiving the error in your layouts, try to 'Invalidate caches & restart'.
Enjoy a coffee while Android Studio is recreating caches & indexes.
I had the same problem and found it was the Theme dropdown at the top of the graphical layout editor. I changed from Holo to Theme and the layout displayed and error disappeared.
What I usually do is the following: a Gradle Clean, Rebuild and Sync all my Gradle files. After that I restart Android Studio, and I go to:
Select Theme -> Project Themes -> AppTheme
This is because you select not a theme of your project. Try to do next:
If we are creating too many projects using Android Studio sometime Rendering issue comes. Even creating a blank activity we receive such rendering error.
Please shut down and restart Android studio. In case the issue persists you can
Hope this helps. It works similar fashion as rule of thumb, in case all looks good and still error persists a restart of application usually resolves the issue.
In my case the problem occurred while the default setting for Android Version in the Designer was set to 'Preview N'. Changed Android Version to '23' and the error notification went away.
Edit And don't forget to uncheck 'Automatically Pick Best'.
I had the same problem using Android Studio 1.5.1.
This was solved by using the Android SDK Manager and updating Android Support Library, as well as Local Maven repository for Support Libraries.
After updating the SDK and restarting Android Studio, the problem was rectified.
Hope this helps anyone who has the same problem after trying other suggestions.
I solved it by changing "classpath" in "dependencies" in build.gradles.
Just change:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-alpha2'
or something like that to:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
I got this error after overriding action bar style like this. Also i lost action bar in preview.
<style name="general_app_theme" parent="#style/Theme.AppCompat">
<!-- for API level 11 -->
<item name="android:actionBarStyle">#style/action_bar_style</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/action_bar_style</item>
</style>
<style name="action_bar_style" parent="#style/Widget.AppCompat.ActionBar">
<!-- for API level 11 -->
<item name="android:height">#dimen/action_bar_height</item>
<item name="android:background">#color/action_bar_color</item>
<item name="android:displayOptions">showTitle</item>
<!-- Support library compatibility -->
<item name="displayOptions">showTitle</item>
</style>
So, problem is overriding theme by my custom. this is the reason, why I've changed AppCompat (from "Project Themes") to general_app_theme (from "Manifest Themes"). Now I have no this error and action bar in preview come back.
Try switching the theme in the design view to one of the options in "Manifest Themes". I'm guessing this is Because you are inheriting the theme from the manifest to support multiple api levels. It worked for me anyway.
With reference to the answer provided by #Benno:
Instead of changing to a specific theme, you can simply choose 'DeviceDefault' from the theme menu. This should choose the theme most compatible with the emulated device.
If you still have the problem after trying all the solutions above, please try modify the API Level as shown below. Incorrect API Level may also cause the problem.
It can be fixed by changing your theme in styles.xml from
Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar
<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>
to
<style name="AppTheme" parent="Base.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>
and clean the project. It will surely help.
Most of the errors in XML happen due to the names you have given to the resources.
Images stored in the drawable folder need to be named in a proper manner.
just check these things:
Are there any duplicate files? if so remove the duplicates. (For example "image.jpg" and "image.png" are not allowed in the same time. It will not show any errors but sometimes it will show that R.java cannot be resolved)
Do the filenames contains any uppercase letters? If so right click on that file->refactor->rename
and rename it with all lowercase, no hyphens, and only a-z and 0-9 are allowed.
Just make sure of the above cases.
I got the same problem with my customized theme that used Holo.Light as its parent. In grayed text Android Studio indicated that some attributes were missing. When I added these missing attributes as follows, the rendering problems went away -
<item name="android:textEditSuggestionItemLayout"></item>
<item name="android:textEditSuggestionContainerLayout"></item>
<item name="android:textEditSuggestionHighlightStyle"></item>
Even though they introduced errors in my style's theme, they caused no problems in rendering the activity designs or building my app.
You can simply remove this error through change "App theme" and select any theme such as light. This error will be removed.
I meet the same problem.Select theme to another one in preview can solve problem temporary.Like the image
Finally,I found out that there are AppTheme and AppBaseTheme in my styles.xml.
And AppTheme has parent AppBaseTheme.
The AppBaseTheme has parent of one system style.
And every layout file use the theme AppTheme.
Just change AppTheme's parent to AppBaseTheme's parent.
It solve the problem permanent.
Just need click button 'AppTheme', and choose 'Manifest Themes'. It works in most cases.
For me, it was occurring on menu.xml file as i was using android:Theme.Light as my theme, So what i did was -
Added new Folder in res directory named values-v21.
Added android:Theme.Material.Light as AppTheme in styles.xml.
This is very late but i like to share my experience this same issue.
i face the same issue in Android studio i tried to some other solution that i found in internet but nothing works for me unless i REBUILD THE PROJECT and it solve my issue.
Hope this will works for you too.
Happy coding.
Change your App theme to AppCombat..

Search View Change Search Menu Item image

When using the theme Theme.Sherlock.Light
and using a searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/location_search_hint"
android:icon="#drawable/action_search"
>
</searchable>
I expect the Search icon to take my own #drawable/action_search which is white but it's ignoring it and it takes the one from the light theme.
How would I be able to change that?
So well, I think I found a solution for your problem.
Add this line to your themes.xml
<item name="searchViewSearchIcon">#drawable/menu_search</item>
There you can "overwrite" the styles like the magnifier icon with your own drawables.
You may also use the other styles like
<item name="searchViewCloseIcon">#drawable/menu_search_close</item>
etc.
Hope this helps,
Tobias
Note the menu needs to have the collapseActionView attribute
android:showAsAction="ifRoom|collapseActionView"
Source
EDIT:
Actually I found a better solution
the Menu can keep the following line:
android:showAsAction="ifRoom"
And the icon for the search need to use the same name as the one from ActionBarSherlock/AppCompat/Native
for app compat it would be abc_ic_menu_share_holo_dark.png

Android theme set to black, but it is white in Android 4.1

I have tried both Theme.DeviceDefault and Theme.Black in my styles.xml, and both make my 2.1 emulator become black correctly, but on the 4.1 emulator it stays white...am I doing something wrong?
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
PS: I presume the drop-down for "Theme" at the top of the Graphical Layout is just showing me what it would look like, it's not some kind of setting that's going somewhere (for the app)?
The Android system always chooses the most special values folder that fits best to your device.
As example if you have a folder values and another folder values-v14 the Android system takes resources from the latter if the device is v14 or newer.
Please refer to the Android documentation for more information.
1.create new folder under res -> values-v13
2.create file style there and add this style :
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
in your manifast use this style for your application like this
<application
android:name=".MainApp"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
that way on ICS version you use the Holo.light theme and pre ICS use the default you already created
Setting it via styles doesn't actually work, but if you set it explicitly for application it works.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black" >
By default 4.0 and 4.1 give us white background but you can change it to black I face the same problem some days ago, if your project theme is set to be black then probably you change the Title while creating project to "Main" by default its "MainActivity" but if you change it to "Main" it will give you black backgrount/
I don't know my answer is relevant to your question or not but i think you talking about this if i am not wrong.

Categories

Resources