I need your help for an issue occured about AppCompat theme. My MainActivity is derived from AppCompatActivity and the theme is declared in the Manifest but when I compile I get this error:
Java.Lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
This is the file containing the theme:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#3F51B5</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#303F9F</item>
<!-- theme UI controls like checkboxes, text fields and switchcompat button-->
<item name="colorAccent">#00FFFF</item>
</style>
And this is manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test_vp.test_vp" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-feature android:name="android.hardware.wifi" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="#string/ApplicationName" android:theme="#style/MyTheme">
</application>
</manifest>
Do You know how can I solve it?
Thank You in advance
Change the first line of code you show:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
to
<style name="MyTheme" parent="#android:style/Theme.AppCompat.Light.NoActionBar">
Also, inside this style definition is where you put children definition to only there you define characteristics like color etc. It's a case of nested definition. Let me try to clear things:
First you define your main style which refers to your secondary style:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
Second, in this same xml you're working, below you define this child style, it is inside this where you choose colors etc. Pay attention with the name of this child theme - must be the same you referenced on parent:
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="colorPrimary">#3F51B5</item>
</style>
In some cases you will have to go deep inside this nesting, defining things by detailed steps. To resume: you can't change things directly, have to specify every detailed portion where you want to customize.
try:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.NoActionBar"></style>
It's in support lib, so ommit the "android:" part.
Related
I am getting the following error
You need to use a Theme.AppCompat theme (or descendant) with this activity
I am following a PluralSight course and I think I missed a crucial step somewhere, but after two days of scratching my head, I can't seem to find the obvious.
Here's my code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.companyname.bethanypieshopmobile"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/BethanysTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
</manifest>
Activity.cs
using Android.App;
using Android.OS;
using Android.Support.V4.View;
using Android.Support.V7.App;
using BethanyPieShopMobile.Adapters;
namespace BethanyPieShopMobile
{
[Activity(Label = "PieMenuWithTabsActivity")]
public class PieMenuWithTabsActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//the line below throws the error
SetContentView(Resource.Layout.pie_menu_tabs);
var viewPager = FindViewById<ViewPager>(Resource.Id.piePager);
var categoryFragmentAdapter = new CategoryFragmentAdapter(SupportFragmentManager);
viewPager.Adapter = categoryFragmentAdapter;
}
}
}
styles.xml
<resources>
<!-- Base application 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>
<style name="BethanysTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/bethanyGreen</item>
<item name="android:colorAccent">#color/bethanyBeige</item>
</style>
<style name="BethanyGreenText" parent="TextAppearance.AppCompat">
<item name="android:textColor">#23cfa7</item>
</style>
</resources>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/piePager" >
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingBottom="12dp"
android:paddingTop="10dp"
android:textColor="#000000"/>
</android.support.v4.view.ViewPager>
add theme attribute to MainActivity
[Activity(Label = "", MainLauncher = true, Theme = "#style/AppTheme")]
OR
change theme in manifest
android:theme="#style/MainTheme"
OR
in styles.xml set BethanysTheme's parent="Theme.AppCompat.Light.NoActionBar"
these links will help you
"You need to use a Theme.AppCompat theme (or descendant) with this activity." Xamarin
You need to use a Theme.AppCompat theme (or descendant) with this activity
https://forums.xamarin.com/discussion/34692/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity
I have my activity with an action bar which I want to customize, however Android is ignoring all my styles...
This is how it looks now:
It should look with a blue background instead and the application logo should be there also...
My manifest is the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="greensmartcampus.eu.smartcampususerfeedbackapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:logo="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/SmartCampusTheme">
<!-- Splash screen while connecting to the web-server -->
<activity
android:name=".HomeScreen"
android:label="#string/title_activity_home_screen"
android:parentActivityName=".AbstractPortraitActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="greensmartcampus.eu.smartcampususerfeedbackapp.AbstractPortraitActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- The activity where all actions take place -->
<activity
android:name=".ControlActivity"
android:label="#string/title_activity_control"
android:parentActivityName=".AbstractPortraitActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="greensmartcampus.eu.smartcampususerfeedbackapp.AbstractPortraitActivity" />
</activity>
</application>
</manifest>
My activity xml is the following:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="greensmartcampus.eu.smartcampususerfeedbackapp.ControlActivity" />
My styles.xml is the following:
<resources>
<!-- Base application theme. -->
<style name="SmartCampusTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBarTheme</item>
</style>
<style name="GenericProgressIndicator" parent="#android:style/Widget.ProgressBar.Small">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:indeterminate">true</item>
</style>
<style name="CustomActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/actionbar_bg_color</item>
</style>
</resources>
I also want to hide those 3 dots in the action bar which open the menu to the settings, which I don't have...
What am I doing wrong?
Thanks!
I believe your issue is related to using the app compatibility library. Try removing the android: prefix from your Actionbar styles. See Styling the Action Bar and appcompat v21.
AppCompat v21 brings the Material theme to all devices. Two changes with this is the use of the new color palette for theming your action bar and activity. In the new system, coloring your action bar is accomplished via a theme such as:
<style name="SmartCampusTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/actionbar_bg_color</item>
</style>
In addition, the lack of the app icon is expected. Per the Toolbar documentation:
In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.
The action bar showing a 'Settings' option is part of the initial template - you can delete the onCreateOptionsMenu method to remove all items from the options menu.
Hi i want to set background image to my application which already has a theme.
<application android:theme="#android:style/Theme.NoTitleBar" />
Now i have changed the code to this
<style name="BackgroundImage" parent="#android:style/Theme.NoTitleBar">
<item name="android:background">#drawable/background</item>
</style>
the manifest file looks like this
<application android:theme="#style/BackgroundImage" />
Now the background image is set but my previous theme i.e. Theme.NoTitleBar is not working.
Ideal behavior expected is both background image and Theme.NoTitleBar should be working. What should i do?
I have changed the style as follows by doing this i am overriding the Theme.NoTitlteBar
<style name="Background" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:windowNoTitle">true</item>
</style>
Now manifest file looks like this.
<application android:theme="#style/Background"/>
you need to do it in the xml file, and not your manifest.
you just have to do somerhing like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yourimage" > //your drawable image here
hope i helped you
I'm trying to implement the ViewPagerIndicator with SherlockActionBar. It works: I can slide the fragments, but the style doesn't work!
It looks like this:
related topic: https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66
I know what's going wrong:
In the sample of VPI, the style of a page is set in AndroidManifest.xml by (for example)
<activity
android:name=".SampleTabsDefault"
android:theme="#style/Theme.PageIndicatorDefaults">
</activity>
But when I add that android:theme element to my own Manifest.xml I get the following exception:
03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
I've also tried to copy all the style-information to styles.xml, but that also doesn't work.
Can you tell me how to set a style to the VPI?
Thank you!
EDIT:
Now I've added
<activity
android:name=".SampleTabsDefault"
android:theme="#style/StyledIndicators">
</activity>
to my Manifest.xml
and the following style in styles.xml
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Result: I don't get any Exception, see the style, but I now I can't see any fragments :(
The code of the activity can be found here: http://pastebin.com/hsNgxFDZ
Screenshot of current page with style:
In order to see the Fragments, you'll have to somehow extend an Android base-theme. In order to see the ViewPagerIndicator, you'll have to somehow include those style-definitions. The answer is to create your own theme that extends the ActionBarSherlock-theme (which extends the Android base-themes), and implements the ViewPagerIndicator-styles.
Example:
<style name="myTheme" parent="#style/Theme.Sherlock">
<!-- If you want to use the default ViewPagerIndicator-styles, use the following: -->
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
<!-- If you want to implement your custom style of CirclePageIndicator, do it like so: -->
<item name="vpiCirclePageIndicatorStyle">#style/myCirclePageIndicator</item>
<!-- Put whatever other styles you want to define in your custom theme -->
</style>
<style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator">
<item name="fillColor">#color/my_custom_circle_indicator_fill_color</item>
</style>
Then in your Manifest, set android:theme="#style/myTheme" to the <application> or to your <activity>s.
Note that you don't have to include all 4 "vpi..."-styles; you only have to include those that you use. E.g. if you're only using the CirclePageIndicator, you only have to include <item name="vpiCirclePageIndicatorStyle">...</item> and can leave out the other 3 item declarations.
I accidentally removed android:layout_weight="1" when adding styles.
So for other who want to implement VPI with ABS:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
style="#style/StyledIndicators" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
styles.xml:
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
etc.
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Thank you #Reinier! :D
The blue shadow over scroll effect looks really ugly in our app.
Is there a way to disable all the over scroll effect? You know there are lots of ScrollViews and Lists in it... That would be a shame if I have to disable it in every widget that can
scroll...
thx~
You can do it simply
In layout.XML
Set
android:overScrollMode="never"
In scrollview
You can define a ScrollViewStyle and ListViewStyle in your Theme:
<style name="Theme.MyTheme" parent="android:Theme.Holo">
<item name="android:listViewStyle">#style/Widget.MyTheme.ListView</item>
<item name="android:scrollViewStyle">#style/Widget.MyTheme.ScrollView</item>
</style>
<style name="Widget.MyTheme.ListView" parent="android:Widget.ListView">
<item name="android:overScrollMode">never</item>
</style>
<style name="Widget.MyTheme.ScrollView" parent="android:Widget.ScrollView">
<item name="android:overScrollMode">never</item>
</style>
Then you have to define your Theme in you AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.citux.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:targetSdkVersion="16" android:minSdkVersion="8"/>
<application
android:hardwareAccelerated="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/Theme.MyTheme">
That's it, no more overscroll ;)
I have face same problem
try this code
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
You can disable all the over scroll effects by opening "res/values/styles.xml" file and adding the item line like bellow:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:overScrollMode">never</item>
</style>
Have you already used setOverScrollMode, with OVER_SCROLL_NEVER?