I'm using Android studio and actually I'm styling Action bar.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#color/oranzova</item>
<item name="android:icon">#drawable/ic_launcher.png</item>
</style>
</resources>
I'm still getting error :
Error:(12, 35) No resource found that matches the given name (at 'android:icon' with value '#drawable/ic_launcher.png').
but no matters which resource I'm using. If i use #raw/icon.png i get still same error. I tried to Invalidate Caches/restart but no help.
You don't need a file-extension like *.png on resource-files. So just change your line:
<item name="android:icon">#drawable/ic_launcher.png</item>
to
<item name="android:icon">#drawable/ic_launcher</item>
Related
I am trying to add a Splash Screen to an existing mobile app for Android using Android Studio. From everything I have researched, I need to be using AppCompat to do this, but each time I try to add it to my styles.xml file, Android Studio tells me "cannot resolve symbol "AppCompat"". Is there somewhere else I should be adding this prior to the styles page in order to have code accept it? My code is below.
Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppCompat">
<item name="android:colorPrimary"></item>
</style>
<style name="SplashTheme" parent="Theme.AppTheme">
<item name="android:windowBackground">#drawable/background</item>
</style>
</resources>
I tried adding it to my AndroidManifest.xml file to no effect, I receive the error "Unknown resource type" in that file.
When I attempted to change my Main file to:
"public class Snake extends AppCompatActivity"
I receive the "Cannot resolve symbol" error again.
I feel like the guides I have read are leaving out some crucial, yet shockingly obvious, step that most people familiar with Android would know quite well. Regretfully, I am still quite new to Android and trying to learn.
So change AppTheme parent to Theme.AppCompat.Light.NoActionBar so styles will be like that:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary"></item>
</style>
<style name="SplashTheme" parent="Theme.AppTheme">
<item name="android:windowBackground">#drawable/background</item>
</style>
You have these error cannot resolve symbol AppCompat because only type AppCompat is not an theme, AppCompat is an symbol inside Themes resouces. So every time you need to set an AppCompat theme you need to type Theme.AppCompat to get the theme AppCompat.
You should have compile "com.android.support:appcompat-v7:25.3.1" in your Gradle dependencies.
You can create a theme with ActionBar and Without ActionBar. If you use a toolbar in your activity probably you should use without action bar theme. Select your theme accordingly.
Create style file like this.
With ActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorPrimary"></item>
</style>
<style name="SplashTheme" parent="Theme.AppTheme">
<item name="android:windowBackground">#drawable/background</item>
</style>
Without ActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary"></item>
</style>
<style name="SplashTheme" parent="Theme.AppTheme">
<item name="android:windowBackground">#drawable/background</item>
</style>
Now refer theme in the manifest. Hope it will work:)
I've tride to set another color for my actiobar quite a while now.
I've search on google and tried multiple solutions. but non of them have worked out for me.
The code i got now is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#cac09f</item>
</style>
</resources>
This causes my app to crash and displays this:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I then tried to set the theme to "Theme.Appcompat" but this wont change the color of the actionbar.
Does anyone know a solution for this?
I run this on a phone running android 4.4.4.
My project is for API 16 and higher (4.1)
You're using an activity from the support package (AppCompatActivity), it can only use compatibility themes (Theme.AppCompat).
The reason why setting a custom action bar background didn't work, is because you also need to use compatibility attributes:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/my_red</item>
<item name="background">#color/my_red</item>
</style>
<color name="my_red">#cac09f</color>
guy I think that would be better you to use a toobar, because it is easier of work.
use this code in your xml:
<android.support.v7.widget.Toolbar
android:id="#+id/tbMain"
android:layout_width="match_parent"
app:theme="#style/style_toobar"
android:layout_height="?attr/actionBarSize"
/>
in the style.xml use this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
<style name="style_toobar" parent="Theme.AppCompat">
<item name="popupTheme">#style/Theme.AppCompat.Light</item>
<item name="colorControlNormal">#color/colorAccent</item>
</style>
in the activity use:
Toobar tbMain = (Toobar)findViewById(R.id.tbMain);
setSupportActionBar(tbMain);
Im trying to create a toolbar but im getting error. I searched and didnt found solution. This is the error:
The following classes could not be found: android.support.v7.widget
my api version is 16.
This is my styles.xml file:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<!-- Customize your theme here. -->
</style>
In my app in setings I use EditTextPreference , and on android API uder 11 edittext field has black background and black text color.
How can I chenge EditTextPreferences background color ?
I tried:
in theme :
<item name="android:editTextPreferenceStyle">#style/EditTextAppTheme</item>
in style:
<style name="EditTextAppTheme" parent="android:Widget.EditText">
<item name="android:background">#drawable/edit_text_holo_light</item>
<item name="android:textColor">#000000</item>
</style>
If I set style to :
<style name="EditTextPreferences" parent="android:Preference.DeviceDefault.DialogPreference.EditTextPreference">
<item name="android:background">#drawable/edit_text_holo_light</item>
<item name="android:textColor">#FF0000</item>
</style>
And theme to :
<item name="android:editTextPreferenceStyle">#style/EditTextPreferences</item>
I got error:
error: Error retrieving parent for item: No resource found that matches the given name 'android:Preference.DeviceDefault.DialogPreference.EditTextPreference'.
I have been trying to figure this out as well for the past couple of days. I've found that all the EditTextPrefence extends is AlertDialog and EditText. So if you can style both of those in your theme, you will find the result you are looking for in a EditTextPreference. Here's what I'm working with:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="LightTheme" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:background">#color/greyscale2</item>
<item name="android:textColor">#color/greyscale16</item>
<item name="android:textViewStyle">#style/LightTextView</item>
<item name="android:buttonStyle">#style/LightButton</item>
<item name="android:editTextStyle">#style/LightEditText</item>
<item name="android:alertDialogTheme">#style/LightDialog</item>
<item name="android:dialogPreferenceStyle">#style/LightDialog</item>
<item name="android:colorBackground">#color/greyscale2</item>
<item name="android:colorBackgroundCacheHint">#color/greyscale1</item>
</style>
<!-- TextView -->
<style name="LightTextView" parent="android:Widget.TextView">
<item name="android:textColor">#color/greyscale16</item>
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Button -->
<style name="LightButton" parent="android:Widget.Button">
<item name="android:textColor">#color/greyscale16</item>
<item name="android:background">#drawable/light_button_background</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
<style name="LightCheckBox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:background">#color/greyscale2</item>
</style>
<style name="LightEditText" parent="android:style/Widget.EditText">
<item name="android:background">#color/greyscale1</item>
<item name="android:editTextBackground">#color/greyscale2</item>
<item name="android:textColor">#color/greyscale16</item>
<item name="android:button">#style/DarkButton</item>
<item name="android:inputType">number</item>
</style>
<style name="LightDialog" parent="#android:style/Theme.Dialog">
<item name="android:background">#color/greyscale2</item>
<item name="android:textColor">#color/greyscale16</item>
<item name="android:textViewStyle">#style/LightTextView</item>
<item name="android:buttonStyle">#style/LightButton</item>
<item name="android:divider">#color/greyscale14</item>
</style>
Notice the
<item name="android:dialogPreferenceStyle">#style/LightDialog</item> attribute in my base theme. I found the styleable resource here, more specifically alertDiaolg here (Note: These can also be found in your SDK directory on your computer)
I hope this at least heads you in the right direction, I have been struggling to figure this out (my first theme in my apps). Happy Coding!
I think the effect you've observed is a bug in the Gingerbread emulator.
After changing the activity's theme and restarting the emulator the EditTextPreference appeared as above.
First extend EditTextPreference and override onPrepareDialogBuilder, inverting background color for versions below Honeycomb:
public class CustomEditTextPreference extends EditTextPreference {
/**
* Prepares the dialog builder to be shown when the preference is clicked.
* Use this to set custom properties on the dialog.
* <p>
* Do not {#link AlertDialog.Builder#create()} or
* {#link AlertDialog.Builder#show()}.
*/
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
}
}
Then replace in your preferences.xml all
<EditTextPreference ... />
with
<your.package.CustomEditTextPreference ... />
I had this exact issue when I switched to the API v21 AppCompat (I think - it previously used to work just fine at least).
My solution was to define the style for android:editTextStyle explicitly in my theme - here is my complete styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:editTextStyle">#android:style/Widget.EditText</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
The result is an editText that looks the same as in #Jesse Webb's screenshot.
To customize a standard style, I use the following XML file :
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="windowNoTitle">true</item>
</style>
</resources>
The problem is that Eclipse tells me that the "windowNoTitle" attribute doesnot exist, but I have cut & pasted it from the example shown in the official web site for styles and themes indicated in the Android dev doc.
How can I modify this standard code to have no title bar?
May be you need to add android: prefix before attriibute name, also you need use valid syntax for the link to parent theme ike this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
You could just add .NoTitleBar at the end so you don't need extra style item.
<style name="AppTheme" parent="android:Theme.Holo.Light.NoTitleBar" />
I used this for fullscreen: <style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
</style>
And it doesn't have Title Bar. Hopefully this helps.