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>
Related
I am trying to stylize the TextInputLayout with an outline. But when I try to use #style/Widget.MaterialComponents.TextInputLayout.OutlinedBox in style attribute my app crashes with this exception:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
Here is the TextInputLayout theme I want to use OutlinedBox
It was working fine but suddenly this error appeared during development
<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
</style>
Global App Theme
<!-- Base application No Action bar theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:fontFamily">#font/opensans_regular</item>
</style>
As reported in the error:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)
You have to change the app theme to a Material Components Theme like:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- ... -->
</style>
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 am trying to add an actionbar similar to soundclouds. I am following the instructions on how to customize the action bar on the android developer website. The error seems to be that the action bar is already being supplied but I am trying to create another one.
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
Here is onCreate():
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
addBirthdayFragment();
Here is the layout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</RelativeLayout>
I have tried to just remove the xml code and java code for the toolbar, in the layout and onCreate respectively, however this is not working; the same error still persists. It must be something to do with the theme I am using, but I do not know what exactly. It confuses me because the theme is the default one so I did not expect this.
Here is my theme:
<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>
Side question:
I am trying to achieve the look of the soundcloud action bar, which appears to be tabbed. Is this the way I should go if I want this result, or is there some other widget that is used for tabbed action bars?
Thank you for the help.
Android is complaining because you never told it that you will use a Toolbar instead of the Android-provided ActionBar. To let Android know about this, you need to add these to your style:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
If you'd like to use the Android ActionBar sometimes and a Toolbar of yours some other time, you can add the above two lines to a new style extending your AppTheme, and using that on AndroidManifest.xml:
<!-- Use this one in the Manifest when you want to use the native ActionBar -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- your styling here -->
</style>
<!-- Use this one when you want to implement your own Toolbar -->
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Your code is:
<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>
The line parent="Theme.AppCompat.Light.DarkActionBar" says dark action bar. you need to change it to NoActionBar.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
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);
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>