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
1
vote
1 answer

How to define a typed array of custom XML objects in Android

I know it's possible to define a typed array of drawables in Android: @drawable/home @drawable/settings @drawable/logout Is it possible to have an array of custom…
William Seemann
  • 3,440
  • 10
  • 44
  • 78
1
vote
0 answers

How to change TabWidget's background color from XML in Android

I have come across this problem. I have a tab widget on top of the view, with four tabs in it. I have been asked to change the background color of the whole tab view area. Not for any tab, but the whole area of that tab view. I also been asked for…
Arthur Wang
  • 3,118
  • 4
  • 21
  • 29
1
vote
1 answer

Android is there any way to reuse a selector for button if the image including in the selector background changes?

I am using the same background shape in a layer list for each button, then in that layer list a specific image related to the function of that button. I know that I can create a selector for each button, however is there any way to reuse a selector…
mgibson
  • 6,103
  • 4
  • 34
  • 49
1
vote
0 answers

Graphical Layout Editor gives nullpointerexception for all XML files in eclipse Juno

the graphical layout editor in my eclipse stopped working, it gives me this message: java.lang.NullPointerException Exception details are logged in Window > Show View > Error Log my Error Log has this in…
1
vote
1 answer

Parsing xml android gives a null pointer exception

I am parsing the following XML: 1 Login Successfull 3 hassan
mdanishs
  • 1,996
  • 8
  • 24
  • 50
1
vote
3 answers

Android Admob Not enough space to show ad

Used the code provided in admob site Here is my xml
Rohit
  • 6,941
  • 17
  • 58
  • 102
1
vote
1 answer

Change TextView on multiple parts of XML layout

I am adding multiple XML Views programmatically. I'm using a layout inflater to add them and there are no problems with that. But I'm not able to modify the TextView in each of them. For example, consider I am adding a LinearLayout three times in…
bharath
  • 953
  • 4
  • 17
  • 30
1
vote
1 answer

Android inflating custom view in XML ClassNotFound error

I have some problems with my XML code i hope you can help me with. I have this class in this package: package com.example.myview public class CustomDialog extends DialogPreference { public CustomDialog(Context context, AttributeSet attrs) { …
1
vote
2 answers

Why are my TextViews being moved around?

I am trying to display a single list item after the user clicks on an item. However, I have noticed that the layout is messed up when there is too much text. Sometimes it's pushed half way, sometimes it's completely to the right side of the screen.…
Johnathan Au
  • 5,244
  • 18
  • 70
  • 128
1
vote
1 answer

Background gradient combined with an image on every page

Is there a way to make a xml file with a gradient for the background of my app and at the same time put the logo in it. So when I set the background of my layout, I get the gradient with my logo on it. Ofcourse it is possible to just define the…
mXX
  • 3,595
  • 12
  • 44
  • 61
1
vote
3 answers

Issues with creating new Android MainActivity

I'm new to Android programming and am attempting to create a new Main Activity for my app (taken from the Android tutorial website). My original Main Activity is called "MainActivity". The new activity I want to be my Main Activity is called…
Nick
  • 51
  • 1
  • 8
1
vote
1 answer

How to apply a common style and theme to our project?

I want to use the same Header in my project . I want to display two image buttons and one textview in the header part. i want to use the same header part to all the screens of my project but want to change the text of textview according to my…
1
vote
1 answer

How do I overcome the issue of a TextView not fitting on the screen and also pushing other content off the screen?

I am trying to build a simple form and I want to add a note/header/title at the top displaying a message. I have tried to do it but the text has gone off the screen and the stuff below it has been pushed off as well. How do I counter this? Here is…
Johnathan Au
  • 5,244
  • 18
  • 70
  • 128
1
vote
1 answer

How to set the distance between the buttons?

I have a problem with my xml file. I have two buttons with custom size. I would like to resize buttons to the similar size in relation to the screens. On the picture 1 you can see how big they should be. On the picture 2 you can see that they are…
Ganjira
  • 966
  • 5
  • 16
  • 32
1
vote
1 answer

why my canvas background isn't full screen (Android)?

I copy pasted the methods of the tutorial rocketscissorpaper on my activity but the problem is that when i run my code the canvas background doesn't appear full screen and I see theres no difference between the two projects, even the xml is the…
Dritan Berna
  • 171
  • 1
  • 3
  • 12