Why is the line android:iconifiedByDefault="false” always ignored, requiring me to always have to find a way to do it automatically? If it’s always going to be ignored, why include it as an option? Am I missing something?
Like most of the Views in the support libraries, the v7 appcompat SearchView uses attributes specific to it that are defined in the app's namespace, rather than the system namespace. This ensures that the attributes can be used in all Android versions that the library supports.
You just need to use your app's namespace prefix on the iconifiedByDefault attribute. For example:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
... >
<android.support.v7.widget.SearchView
...
app:iconifiedByDefault="false" />
</RelativeLayout>
Related
So, I have a Layout that is
android:visibility="invisible"
is there a way to force ui designer in intellij idea to display such elements at all times?
According to the documentation you can use the tools xmlns:
tools:visibility="visible"
Android Studio supports a variety of XML attributes in the tools
namespace that enable design-time features (such as which layout to
show in a fragment) or compile-time behaviors (such as which shrinking
mode to apply to your XML resources). When you build your app, the
build tools remove these attributes so there is no effect on your APK
size or runtime behavior.
To use these attributes, add the tools namespace to the root element
of each XML file where you'd like to use them, as shown here:
<RootTag xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
Use this tools:visibility="visible"
I upgraded to Android Support Library 23.2.0 and added
vectorDrawables.useSupportLibrary = true
to my build.gradle, so that I have vector drawable support for apis lower than 21. (See here for details).
I also replaced
android:src="#drawable/ic_create_black_24dp"
with
app:srcCompat="#drawable/ic_create_black_24dp"
in every Imageview that uses vector drawables.
The app compiles and works perfectly fine, but code analysis reports:
Error:(56, 9) Unexpected namespace prefix "app" found for tag ImageView
Why is this the case? Why is it compiling although I am getting errors?
EDIT: I have added
xmlns:app="http://schemas.android.com/apk/res-auto"
in my root layout.
Lint, Android's code analysis tool, doesn't seem to know about support vector drawables, yet. You can safely ignore the error by adding tools:ignore="MissingPrefix" to the ImageView tag.
Change ImageView to android.support.v7.widget.AppCompatImageView in your XML
You're seeing this error, because original ImageView doesn't have srcCompat attribute. This attribute is used only by AppCompatImageView, which is injected instead of ImageView you declared. This error is easy to spot when using overloaded view inflaters. Lint performs static analysis and doesn't know about hacks you can do with xml from code.
Need to add this to top parent layout :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
Add xmlns:app="schemas.android.com/apk/res-auto" as attribute either to your ImageView or to the Top-Level Tag like LinearLayout, CoordinatorLayout, RelativeLayout.. etc
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/ic_create_black_24dp"
xmlns:app="http://schemas.android.com/apk/res-auto"/>
or in parent layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"/>
What is the difference between given two namespace decalration in Android.
xmlns:app="http://schemas.android.com/tools"
and
xmlns:app="http://schemas.android.com/apk/res-auto"
I am getting lint warning on using http://schemas.android.com/tools => Suspicious namespace and prefix combination
I know using http://schemas.android.com/apk/res-auto will solve the issue, but want to know the reason behind it.
Below namespace is used for android predifined components.
xmlns:app="http://schemas.android.com/tools"
But if you want to use custom components like appCompat or your custom defined views you have to use the other namespace as well
xmlns:app="http://schemas.android.com/apk/res-auto"
I am using this famous ViewPagerIndicator library in my project. I wanted to add color on ViewPageIndicator. I found a solution from here on StackOverflow.
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
app:fillColor="#FF888888"
app:pageColor="#88FF0000"
app:strokeColor="#FF000000" />
But one thing I can't understand here: why it is written app: instead of android:? What does app: mean? I have never used app:? What is its namespace? I googled but no solution found.
For the namespace, add this: xmlns:app="http://schemas.android.com/apk/res-auto"
The app namespace is used for all 'new' attributes. For example: if I make a custom view, that has its own attributes (let's say RainbowView with new attribute 'numberOfColors'), then I have to use that attribute in the app namespace because it isn't declared in the android namespace. So use the app namespace for all custom attributes. Either attrs you defined yourself, or attrs the author of a library added (in your case for CirclePageIndicator). But most of the time, when you start typing 'strokeCo...' and you see 'strokeColor' in the autocomplete list, the namespace will be added automatically when you select it.
Probably you only need to add the missing namespace:
xmlns:app="http://schemas.android.com/apk/res-auto"
Or take a look at this answer for referencing a library:
How can I set up custom namespaces in layout file in Android studio?
For example, in:
<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" >
...
Do I need to put it?
It defines the XML namespace of the document. You should put it, otherwise tags like <RelativeLayout> could be not recognied by the parser.
Namespaces are a way for XML documents to include tags from various vendors. By using xmlns attribute you declare, that, by default, you're using XML elements defined here: http://schemas.android.com/apk/res/android (note that this link is broken - this discussion explains why).
You also declare additional namespace, tools, which is not your default namespace, thus when referencing elements or attributes defined there, you must add tools prefix, on example:
tools:context=".SomeActivity"
Following is a useful link from Android dev portal: https://developer.android.com/studio/write/tool-attributes.html
It says
Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.
i.e. tools namespace helps designing UI and all attributes with prefix 'tools' will be removed at build time.
In fact, when you do :
<RelativeLayout android:id> </RelativeLayout>
Instead of calling android:id, the xml will call http://schemas.android.com/apk/res/android:id . It just the page that declare all the attribute and views that you can use in your xml.
Here is an explanation.
http://www.w3schools.com/xml/xml_namespaces.asp