Configure Eclipse for Material Design - android

How do I configure My App to use Material Theme. I don't wanna use Android Studio because its too slow and freezes a lot. I have read the instructions from answer to similar question.
I followed the steps but I didn't get values-21 folder as mentioned in the answer. What can I do now?

There is no difference at project folders structure in this case in Eclipse and AS, maybe you just can't get right preview at Eclipse.

I'm assuming that you currently have a folder res/values that has a file styles.xml which contains your apps theme. Manually create a folder res/values-v21 and copy your styles.xml into it. Modify the new file now so that it uses the material theme as its parent.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Material">
<!-- Customize your theme here. -->
</style>
</resources>
Now when your app is run on a device/emulator running API 21+ it will use the Material theme.

Related

Android Studio 1.3: Theme.Material.Light and Theme.Material Giving Error

I am trying to make an Android Application with Material Design. My initial problem was that the v22 styles.xml wasn't present in the values folder. However, I fixed that issue with the following link from Stackoverflow:
values-21, values-22 or values-xx folder is gone after Android Studio 1.0
Then, when I changed my new v22 styles.xml theme to Theme.Material.Light, it showed an error and appeared red. In the above link, bijang tells Pankaj to download and put a certain themes_material.xml file into the values folder. The existing Theme.Material.Light error goes away, but in that file (whose source code can be found here: https://gist.github.com/jbj88817/b0a3f750e3fe705a8a1a) It shows an error as follows:
Theme.Material, where THEME is the error. Please help!
Here is my v22 styles.xml:
<resources>
<style name="AppTheme" parent = "Theme.Material.Light">
</style>
</resources>
Since after the SDK for api 22 was introduced. You don't need a separate styles.xml for v22 or v21. So in values res folder have only one styles.xml(default one) and to support material design use Theme.AppCompat.
Example
<style name="AppTheme" parent="Theme.AppCompat">
</style>
And in addition use AppCompatActivity instead of ActionBarActivity for your activity.
Example
public class MainActivity extends AppCompatActivity

How to get rid of rendering issue in Android Studio that refers to resource that isn't found in project?

The "Rendering problem" states Couldn't resolve resource #style/Widget.Holo.Actionmode but when I do a project/path search for Widget.Holo.Actionmode it isn't there.
As a result, my soft numeric keypad won't display.
What the heck do I do? I've changed the styles in the Android Studio 1.1.0 dropdown in design mode but no matter what I choose I get the rendering problem and no keypad. I had colors set to Holo this and that because I liked the shades and I had Holo as the theme from the dropdown. I also have in AndroidManifest.xml this:
android:theme ="#style/AppTheme"
But when it was working, I had commented that out to get nice black background. Either way, no keypad.
All I have in styles.xml is this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.ThemeOverlay.AppCompat">
<!-- Customize your theme here. -->
</style>
</resources>
I exited and re-entered AS. No keypad; same problem.
I'll post all xml and activity java code if need be. This is insane.
Looks to me like there's a problem in APIs 17 & 18 with the definition of Widget.Holo.ActionMode. I added the following to my styles.xml file:
<!-- Put this here to fix rendering error in API 17-18 -->
<style name="Widget.Holo.ActionMode" parent="#android:style/Widget.Holo.ActionMode">
<item name="titleTextStyle">#android:style/TextAppearance.Holo.Widget.ActionMode.Title</item>
<item name="subtitleTextStyle">#android:style/TextAppearance.Holo.Widget.ActionMode.Subtitle</item>
</style>
This may happen on APIs below 17, haven't tested. It was fixed in 19.

why android application logo is not coming in 5.0 version?

After updating my device's android version(lollipop), my app's logo is not displaying in lollipop version. and color of action bar has changed.
I am using following theme in my application
android:theme="#android:style/Theme.DeviceDefault.Light"
What would be the issue?
Umm.. that style is follows device's default style.
If you want same style for all devices, set style like this. android:theme="#android:style/Theme.Holo.Light"
Then you can see style with app logo like as before for all devices & versions.
Or if you want Material style. you might be using Toolbar.
http://developer.android.com/reference/android/widget/Toolbar.html
You have to do few changes:
parent="#style/Theme.AppCompat.Light" need to applied in your
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
</style>
</resources>
And then goto
File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"
then
Project-> properties->Android. Select tab library "Add" and choose "appCompat"

Holo Theme and API 8

I have an app that must be supported from API 8+. But I also like to have my app the holo theme for(11+). I know it won't be supported as the min sdk is 8. So the only solution will be to create 2 separate apps one for 8-11 and one for 11+. Is there any better way to do this? So that I can reduce double maintenance.
There's no need to create two separate apps. You just need to create two definitions of theme for your app:
styles.xml in /res/values-v11 (Will be used only on API 11+)
<resources>
<style name="app_theme" parent="android:Theme.Holo.Light"/>
</resources>
styles.xml in /res/values
<resources>
<style name="app_theme" parent="android:Theme.Light"/>
</resources>
and then, apply it to your application in AndroidManifest.xml:
<application
...
android:theme="#style/app_theme"
>
...
</application>
This setup uses resource qualifiers. You can read more about them here.
You can try the HoloEverywhere library to use Holo theme on Android 2.1+. It also integrates well with ActionBarSherlock.

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..

Categories

Resources