Questions tagged [android-xml]

Android projects use XML in several ways: defining the project and components, building layouts, defining animations, creating menus and specifying resources (static and dynamic) for the project.

Introduction

In addition to Java code, Android projects (and their developers) have the ability to utilize XML to perform many standard tasks. Some XML usage is required, such as the definition of the projects and its components. Much of XML's usage is optional, making many common tasks easier. The Android XML schema is highly flexible and may be used in combination with code, exclusively, or not at all. Below is a list of common usage of XML:

  • Manifest - definition of the project
  • Layout - creation of partial or complete layouts for Activities, Dialogs, and Widgets
  • Colors - Constant color values used throughout the project
  • Style & Themes - application of custom standardized looks of Views
  • Animations - Standardized animations that may be applied to Views.
  • Drawables - Some specialized icons and graphics that may not be created wholely with an image editor. (StateDrawables, TranstionDrawables, Shapes and VectorGraphics)
  • Menu - A resource used to aid in standardized menus for an Activity
  • Integers, Strings, and Arrays - Constants used by the Application as resources.

AndroidManifest.xml

This file is a core component for every Android project. In order for nearly every component to work, it must be declared in the Manifest. The Manifest may affect everything from type of instancing to meta-data, even security restrictions. A comprehensive resource for the AndroidManifest.xml file exists at the Android Developers Dev Guide. Questions regarding the Android Manifest should use the android-manifest tag instead.

Android Layout XML

Android Layout may be partially or fully defined in XML to modularize presentation and limit code. The capabilities of Android Layout XML are quite extensive, allowing nearly every aspect of presentation to be managed in pure XML. Questions regarding layout should also use the android-layout tag.

Resources (Integers, Arrays, Strings, Colors, Styles, Themes, Menus)

One of the predominant uses of Android XML is to define resources that may be used by the entire application code base, similar to that of constants. Since so much of resource definition has been standardized throughout software development as a whole, XML provides a way to define these without having to manually generate much code that puts these to use. Before posting a question, it is best to make sure it is not covered by these documents:

Drawables and Animations

Android allows you to define special drawables or animations via XML. The ability to dynamically generate graphics and animation can significantly reduce code and further separate presentation from implementation. Questions regarding either of these should also utilize the animation tag or drawable tag respectively.

3013 questions
80
votes
3 answers

android - apply selectableItemBackground in xml with support v7

even with android support v7 included in my application adding android:background="?android:attr/selectableItemBackground" makes my IDE, Eclipse throw an error (preventing me from compiling), notifying me that selectableItemBackground is only for…
CQM
  • 42,592
  • 75
  • 224
  • 366
78
votes
2 answers

Vertical content align in Android EditText

I have a multi-line EditText:
74
votes
9 answers

Toolbar in AppBarLayout is scrollable although RecyclerView has not enough content to scroll

Is it really intended that the Toolbar in a AppBarLayout is scrollable although the main container with the "appbar_scrolling_view_behavior" has not enough content to really scroll? What I have tested so far: When I use a NestedScrollView (with…
68
votes
3 answers

Activity Layout: Fragment class: vs android:name attributes

I've read the documentation about Fragments in the Android Developer Guide and I've seen that sometimes they specify the class to instantiate with the Fragment tag attribute android:name and sometime they use the class: attribute:
Gianni Costanzi
  • 6,054
  • 11
  • 48
  • 74
64
votes
7 answers

Getting a String from Plurals to use in XML?

I am using Plurals to simplify my code. e.g., I used to have Cat Cats Using Plurals instead of multiple strings, I now have Cat
Duke
  • 843
  • 1
  • 8
  • 10
64
votes
1 answer

How can I draw circle through XML Drawable - Android?

I'm trying to draw circle with the help of XML file in android, but circle is not displaying properly. Below code is showing Oval. How can I create circle in XML file.
VATSHAL
  • 1,529
  • 2
  • 12
  • 12
63
votes
3 answers

How to change the height of the 'Log in with Facebook' button?

I already tried several answers I could find but none of them worked with the latest Facebook Android SDK version 4.0. How can I change the layout height with the latest SDK?
Steffen
  • 2,197
  • 2
  • 24
  • 38
55
votes
10 answers
53
votes
5 answers

i want to make my application only in landscape in android

I want to make my app work only in landscape mode but can't make it work. I have given screenOrientation = "landscape" even though the first page will be in landscape mode and other activity will be in portrait. XML FILE
shripal
  • 1,222
  • 4
  • 19
  • 40
52
votes
5 answers

how to change color of the actual scroll in ScrollView android?

I'm wondering if it's possible to change the color of the ScrollView. I'm not referring to the background color or the edges. I attached a print screen of the bar I'm referring. For me, it's kind of transparnt. Here's how I defined it in the xml:…
dusm
  • 1,207
  • 4
  • 18
  • 24
52
votes
6 answers

Custom designing EditText

I have custom designed EditText search_page.xml
Devrath
  • 42,072
  • 54
  • 195
  • 297
51
votes
7 answers

Unexpected namespace prefix "xmlns" found for tag LinearLayout

I am having an error in following xml file. "Unexpected namespace prefix "xmlns" found for tag LinearLayout". I tried the solutions provided in other similar questions also but it didn't work for me. Same error is occurring in 3 lines where…
khushalbokadey
  • 1,132
  • 1
  • 11
  • 25
48
votes
2 answers

ImageView not keeping max height and width

I load an image into an ImageView using .setImageURI(selectedImageUri) that is retrieved from the user's photo gallery. I have the image view restrict the size with android:maxHeight="150dp" android:minHeight="150dp" android:maxWidth="150dp"…
bwoogie
  • 4,339
  • 12
  • 39
  • 72
48
votes
10 answers

error: Error parsing XML: not well-formed (invalid token) ...?

I am working on an application, with following XML. but whenI try to clean/build my project the following error occurs: "error: Error parsing XML: not well-formed (invalid token)"
Usama Sarwar
  • 8,922
  • 7
  • 54
  • 80
46
votes
2 answers

Are there any side-effects of using multiple string.xml files?

I am currently creating an application that have some strings (>300 for now) and I have some problems to quickly find a string with so many of them. So I was considering the possibility of using several string.xml files instead of only one…
sam
  • 3,441
  • 2
  • 33
  • 42