Error in Main.xml - java

I am getting the error: error: No resource identifier found for attribute 'showAsAction' in package:
I cannot find out why I am getting this error but I have been at it for hours without any sort of break through. I have searched google with many different resolutions but none that appear to work for me.
I would be grateful if someone could help direct me towards a fix to the error.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.nibbler.zoe.liteplayer.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>

Most likely showAsAction is not your attribute, hence not available in app: namespace. Did you mean android:showAsAction?

If u are having min ver below 14 and u want to add showAsAction for below 14 api devices, then u can use this.
1.)U need support library to be added in build path.
2.)Need to add app theme as Theme.appcompat.
3)Rest are as u are using means add ur own namespace with .../res-auto value and use that name with showAsAction
You can add support lib res like this http://developer.android.com/tools/support-library/setup.html
You need to extends ActionBarActivity instead of Activity.
For complete Action bar guide follow the link http://developer.android.com/training/basics/actionbar/setting-up.html

Related

How to change app:elevation programmatically

My app is work for API 19. So I can't use android:elevation. So I app:elevation in my layout.
Android XML: android:elevation vs. app:elevation
For exemple :
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="5dp">
How to change app:elevation programmatically ? I can change android:elevation but I can't find how to change app:elevation !
Try with using the following code
ViewCompat.setElevation(View, float)
Following the below link. Here showed how to make elevation on pre-lollipop device
Android AppCompat 21 Elevation
The accepted answer won't actually work. The answer should have been updated.
If you look at why mAppBarLayout.setTargetElevation(0) is deprecated. it states that:
#deprecated target elevation is now deprecated.
AppBarLayout's elevation is now controlled via a {#link android.animation.StateListAnimator}.
This method now always returns 0.
So to programmatically set the appbar layout you can only do it by creating a StateListAnimator such as appbar_state_unelevated_animator at the animator res folder:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<objectAnimator
android:propertyName="elevation"
android:valueTo="4dp"
android:valueType="floatType"
android:duration="100"/>
</item>
then loading it in code like so:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appbar.stateListAnimator = AnimatorInflater.loadStateListAnimator(applicationContext, R.animator.appbar_state_unelevated_animator)
}
If I'm not mistaken you could also create a StateListAnimator by code but don't take my word for it.
Update:
In my experience when you set the
app:elevation="//Any DP value//"
The Shadow of the app bar will be lost. Simple remove that line to get the appbar shadow again.
I would like to provide updated and full answer:
switch (state) {
case On:
appBarLayout.setStateListAnimator(AnimatorInflater.loadStateListAnimator(getContext(), R.animator.appbar_elevation_on));
break;
case Off:
appBarLayout.setStateListAnimator(AnimatorInflater.loadStateListAnimator(getContext(), R.animator.appbar_elevation_off));
break;
}
appbar_elevation_on.xml under RES\animator
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="PrivateResource">
<item>
<objectAnimator
android:propertyName="elevation"
android:valueTo="#dimen/design_appbar_elevation"
android:valueType="floatType" />
</item>
</selector>
appbar_elevation_off.xml under RES\animator
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="PrivateResource">
<item>
<objectAnimator
android:propertyName="elevation"
android:valueTo="0dp"
android:valueType="floatType" />
</item>
</selector>
Since you try to change the elevation of the Action bar you can easily use this line, which will work on API 19
getSupportActionBar().setElevation(0);
or you follow this link and check out how to change the elevation of views on Android below API 21 generally
Android AppCompat 21 Elevation
Accepted answer didn't work for me.
To remove shadow in Toolbar use
app:elevation="0" in AppBarLayout xml or
use mAppBarLayout.setTargetElevation(0) in java.
It worked in my case.
The following solution is for NativeScript
let nativeAnView = tnsView.android;
var shape = new android.graphics.drawable.GradientDrawable();
shape.setShape(android.graphics.drawable.GradientDrawable.OVAL);
shape.setColor(android.graphics.Color.parseColor('#30bcff'));
nativeAnView.setBackgroundDrawable(shape);
nativeAnView.setElevation(20);
on Android
let nativeView = tnsView.ios;
nativeView.layer.shadowColor = new Color('#888888').ios.CGColor;
nativeView.layer.shadowOffset = CGSizeMake(0, 2.0);
nativeView.layer.shadowOpacity = 0.5;
nativeView.layer.shadowRadius = 5.0;
on iOS

Android not recognizing string resource

In my android app, I have a string
<string name="action_upload">Upload Image</string>
in the strings file. Then in a menu file I have
navigation_screen.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="android.arin.NavigationScreen" >
<item
android:id="#+id/action_upload"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_upload"/>
<item
android:id="#+id/action_forward"
android:icon="#drawable/ic_action_forward"
android:title="#string/action_forward"
android:showAsAction="ifRoom" />
</menu>
However when I try to run it, I get an error saying:
[2014-06-19 17:26:18 - ARIN] W/ResourceType( 9060): ResXMLTree_node size 0 is smaller than header size 0x100.
[2014-06-19 17:20:26 - ARIN] C:\Users\NAME\Documents\NAME\NAME\ARIN\res\menu\navigation_screen.xml:5: error: Error: No resource found that matches the given name (at 'title' with value '#string/action_upload').
I even tried a Project clean in eclipse, but still problem persists.
Does anyone know how to fix it?
Thanks
This may seem like a weird answer, but did you save the xml file. Hit Ctrl-S and try it again.
If that doesn't work: Are the other strings you declared in the strings.xml file visible?

error: Multiple annotations found at this line:

I am implementing searchview in my app, for which I copied this options_menu.xml from a separate working project of searchview.
I get this error in res/menu/options_menu.xml
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'actionViewClass' in package
'com.example.indianconstitution'
- error: No resource identifier found for attribute 'showAsAction' in package
'com.example.indianconstitution'
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search" // error in this line
android:icon="#drawable/ic_launcher"
android:title="#string/action_search"
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:showAsAction="always" />
</menu>
Can anyone figure out this problem?
Thanks in advance...
Looks like you copied this from a project that uses appcompat-v7 into one that doesn't.
Either include appcompat-v7, following the instructions, or just replace yourapp:x attributes with android:x attributes. If you go this way, though, you should also replace the action view class with the corresponding one in the framework (i.e. android.widget.SearchView).

Java move <Preference> from one PreferenceScreen to another?

I'm trying to do something similar to iOS editable UITableView. I have a list of "added items" if the user clicks on "Add new item" he is taken to a PreferenceScreen with multiple <Preference> elements, onclick the should disappear from this screen and add it to the "Added list" (actually a <PreferenceCategory>), then they should be able to remove them from here or edit their order. This is similar to iOS editable lists.
This is my XML:
<PreferenceScreen android:title="ALL APPS" android:key="app_list">
<!-- A <preference> for each app -->
</PreferenceScreen>
<PreferenceCategory android:title="ADDED APPS" android:key="my_apps_list">
</PreferenceCategory>
I have tried uncountable times and I cannot get it to work.
How can I get it done?
I've experimented around a bit and it's actually very easy when you nest your PreferenceScreens.
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference android:title="Check it!" />
<PreferenceScreen android:title="To the other preferences!" android:summary="I really hope this works <3" >
<EditTextPreference android:title="Edit your name" android:summary="Edit your name :)" />
<CheckBoxPreference android:title="Accept answer" />
</PreferenceScreen>
</PreferenceScreen>
PS: Please excuse my hard-coded string literals - it was just for testing! :)
this looks like a very similar question to what i've asked in the past:
android - showing listView in PreferenceActivity
when selecting the items to show , store them in some way (DB ,references ,etc...) and then use the solution i've found .
as you can see , the view used in preference activity is actually a listView , so it's weird to put a listView in a listView . what you need is a special trick , and that's something i've written about .
Please have a look to the accepted answer on this question:
How to remove Android preferences from the screen
Sometimes, if categories are present, you have to
"reference the category containing the preference you wanted to remove and then remove that preference from that category"
like the answer there says. Isn't this also your case?
Hope this helped.

Change selection color on Button's and TextView's in Android

I'm developing an app and when I run it in the Emulator and I've selected a button (not clicked!) it shows an orange layer over it. When i click it i turns yellow.
On a HTC device the orange/yellow overlay is green. On a Samsung Galaxy S it's blue.
I want my app to have the same selection color's throughout the whole app (Blue to be precise).
Is this possible? If so, how?
I think link provided below could be helpful for you
link is: http://groups.google.com/group/android-developers/browse_thread/thread/a7ff938ce09e7c37
Yes it is possible. Use Themes to apply style to the whole app.
You r right
But u also set background color at runtime
& Another
possibility that may be HTC /Samsung has different Android Version ?
so this Happen
Create a selector in your drawable folder
for example drawable/item_selctor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/item_button_selected"
android:state_pressed="true" />
<item android:drawable="#drawable/item_button_selected"
android:state_focused="true" />
<item android:drawable="#drawable/item_button_selected"
android:state_selected="true" />
<item android:drawable="#drawable/item_button" />
</selector>
In your code or xml file use
item.setBackgroundResource(R.drawable.item_selector);
in code
or
android:background="#drawable/item_selector"
in xml layout file

Categories