I'm trying to use Fragments and ActionBar in a Android 2.2 project. There is some error when using "?android:attr/actionBarSize", how to get and set that value correctly?
Example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frags">
<fragment class="com.example.android.hcgallery.TitlesFragment"
android:id="#+id/frag_title"
android:visibility="gone"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_width="#dimen/titles_size"
android:layout_height="match_parent" />
<fragment class="com.example.android.hcgallery.ContentFragment"
android:id="#+id/frag_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Error: No resource found that matches the given name (at 'layout_marginTop' with value '?android:attr/actionBarSize').
You should just use:
android:layout_marginTop="?attr/actionBarSize"
See http://developer.android.com/training/basics/actionbar/overlaying.html
"...The one with the android: prefix is for versions of Android that
include the style in the platform and the one without the prefix is
for older versions that read the style from the Support Library..."
For me replacing
android:layout_marginTop="?android:attr/actionBarSize"
with
android:layout_marginTop="?attr/actionBarSize"
helped to launch app on Android 2.2 and Android 4.3 without any issues.
I think the problem is that actionbar comes with android 3.0 and you are using 2.2. But there is a way to skip this by a extension called "actionbarsherlock".
Related
I'm using data binding library and I experience following issues in Android Studio 3.0:
somelayout.xml:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="meeting"
type="some.package.MeetingStatusResponse"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{meeting.title}"
tools:text="Title"
/>
...
</LinearLayout>
</layout>
In this place: android:text="#{meeting.title}" Android Studio 3.0 underlines the # symbol and informs about error:
Error:(29, 27) <expr> or <lambda expression> expected, got '#'
Model class is written in Kotlin if it has any relevance.
The code completion is also not working for bound classes. The application can be successfully build using both, gradle command and Android Studio run app button. So this is just editor issue.
I observe this issue on Mac. On Windows it works ok. I do not have more computers to check if it's platform related issue.
Maybe you forgot to add in gradle compileOptions ?
`sourceCompatibility JavaVersion.VERSION_1_7`
`targetCompatibility JavaVersion.VERSION_1_7`
I have the following layout in Android Studio 2.1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.kea.trimetrail.MainActivityFragment"
tools:showIn="#layout/activity_main">
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapbox:accessToken="#string/mapbox_access_token"/>
</RelativeLayout>
It displays the following error:
No resource identifier found for attribute 'accessToken' in package 'com.example.myapp'
In this case, the error is generated building a simple Mapbox application. I'm developing mapbox from source (yes, I need the source build, not the pre-built).
See:
https://github.com/mapbox/mapbox-gl-native/blob/master/INSTALL.md
The source tree is for multiple platforms, I'm using:
https://github.com/mapbox/mapbox-gl-native/tree/master/platform/android
The source build is located as a dependent library located at:
myapp/app/libs/mapbox-gl-native/platform/android
I've tried importing the module and more using other similar posts, but nothing helps.
While a solution to my particular issue would be awesome, simply understanding the cause of the message might help too. Everything I read is about specific solutions to similar messages, but I can't find any information about the message itself.
Thx
Not sure, but looks like they changed the name from accessToken to access_token. I can't tell for sure because this just brings up a new error. I'll assume the new error is something beyond the old error and not instead of.
Problem is that just I can't user overlayTop but I've got Support Design Library 23.1 included and every component usable just this one not
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nes_scroll"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:behavior_overlayTop="44dp">
...
and here's error:
Error:(50) No resource identifier found for attribute behavior_overlayTop in package com.scroll.example
also it's not usable in Java source too, it's just red line and offers to create class related to setOverlapTop().
The Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_weight = "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:id="#+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
The error message:
BUILD FAILED
C:\My First App\res\layout\activity_main.xml:7: Unexpected element "{}LinearLayout" {antlib:org.apache.tools.ant}LinearLayout
The code is almost exactly the same as the code on the Android website and it's really frustrating that I can't seem to get it to work. Is the problem in the code, or is it on my side? I am using Eclipse
I was getting the same error. I was using Indigo in Ubuntu 12.04, and no matter what libraries I got or eclipse plugins I used it was always there.
What worked for me was re-downloading and reinstalling the Android SDK (probably not necessary in your case), and downloading Eclipse Classic (Juno) from the Eclipse website rather than using the Indigo package that was in the repos. The lesson said Classic was recommended anyway, so whatever, I'm just happy it works now.
If you are using Windows, I'd still suggest downloading the most recent Classic version, but otherwise I can't be of help there.
I faced this strange problem.
On my layout xml, I have a single TextView, and in it I have the following text:
"Welcome to App.\n etc" , defined in strings.xml.
In a tablet running 4.0 displays the full string.
In a smartphone running 2.3.7 it displays just before the \n.
On previous apps I have created, \n worked okay.
Anybody faced something similar?
XML Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textViewWelcomeNotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:layout_centerVertical="false"
android:layout_margin="15dp"
android:layout_marginTop="20dp"
android:fitsSystemWindows="false"
android:focusableInTouchMode="true"
android:gravity="center_vertical|center_horizontal"
android:hint="#string/msgWelcomeNotesHint"
android:paddingTop="10dp"
android:text="#string/msgWelcomeNotes"
android:textSize="14dp" />
</RelativeLayout>
It was a weird bug of latest ADT 20.0, in Eclipse Juno.
I made a fresh install of Eclipse Juno, because i heavily loaded it with plugins,
and now \n appears okay, in the same apk, on 2.3 and 4.0+ Android Versions.
Also some other bugs, eg when creating new activity (New->Other->Android Activity), exist on this ADT.