Skip to main content
Android Code Studio provides comprehensive XML language support specifically tailored for Android development, including smart completions for layouts, manifests, and resource files.

Language Server Features

The XML Language Server (XMLLanguageServer) offers specialized support for Android XML files:

Context-Aware Completion

Intelligent suggestions based on file type (layout, manifest, drawable, etc.)

Android Attributes

Complete android: namespace attributes with value suggestions

Resource References

Auto-complete @string, @drawable, @color, and other resource references

Code Formatting

Automatic XML formatting with configurable indentation and line breaks

File Type Support

The XML LSP recognizes and provides specialized completion for different Android XML file types:

Layout Files

Layout files in res/layout/ receive specialized completion:
Completion for Android View classes and custom views:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <!-- Type 'Text' to complete TextView, EditText, etc. -->
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name" />
    
    <!-- Type 'Button' for Button completion -->
    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Click Me" />
        
</LinearLayout>
Implementation: Layout completion is handled by LayoutTagCompletionProvider and LayoutAttrCompletionProvider (source: xml/lsp/src/main/java/com/tom/rv2ide/lsp/xml/providers/completion/layout/)

AndroidManifest.xml

Specialized completion for manifest elements:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    
    <!-- Type 'uses-' for permission declarations -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        
        <!-- Type 'activity' for activity declaration -->
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <!-- Type 'action' for intent actions -->
                <action android:name="android.intent.action.MAIN" />
                <!-- Type 'category' for intent categories -->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <!-- Type 'service' for service declaration -->
        <service
            android:name=".MyService"
            android:enabled="true"
            android:exported="false" />
            
    </application>
    
</manifest>
Implementation: Manifest completion uses ManifestTagCompletionProvider, ManifestAttrCompletionProvider, and ManifestAttrValueCompletionProvider

Drawable XML Files

Completion for drawable resources (res/drawable/):
button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    
    <!-- Type 'solid' for solid color -->
    <solid android:color="@color/primary" />
    
    <!-- Type 'corners' for rounded corners -->
    <corners android:radius="8dp" />
    
    <!-- Type 'stroke' for border -->
    <stroke
        android:width="2dp"
        android:color="@color/primary_dark" />
        
</shape>
Implementation: Drawable completion uses DrawableTagTransformer to provide context-specific suggestions

Animation Files

Support for animation XML files:
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    
    <!-- Type 'alpha' for alpha animation -->
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="300" />
        
    <!-- Type 'scale' for scale animation -->
    <scale
        android:fromXScale="0.8"
        android:toXScale="1.0"
        android:fromYScale="0.8"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="300" />
        
</set>
Implementation: Animation files use AnimTagTransformer and AnimatorTagTransformer for type-specific completion Completion for menu resources:
main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    
    <!-- Type 'item' for menu item -->
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_search"
        android:title="@string/action_search"
        app:showAsAction="ifRoom" />
        
    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="never" />
        
</menu>
Implementation: Menu completion provided by MenuTagTransformer

Completion Providers

The XML LSP uses a provider pattern for different completion contexts:

Tag Completion

Provides suggestions for XML element names:
  • LayoutTagCompletionProvider: Android View classes
  • ManifestTagCompletionProvider: Manifest elements (activity, service, receiver, etc.)
  • SimpleTagCompleter: Simple tag name completion
  • QualifiedTagCompleter: Fully qualified class names

Attribute Completion

Suggests available attributes for a given element:
  • LayoutAttrCompletionProvider: View attributes
  • ManifestAttrCompletionProvider: Manifest attributes
  • CommonAttrCompletionProvider: Common XML attributes
  • InheritingAttrCompletionProvider: Attributes inherited from parent tags

Attribute Value Completion

Provides value suggestions for attributes:
  • AttrValueCompletionProvider: Resource references, enum values, booleans
  • ManifestAttrValueCompletionProvider: Manifest-specific values (permissions, features, etc.)

Code Formatting

The XML formatter (CodeFormatProvider) provides automatic formatting:

Formatting Options

class XMLFormattingOptions {
    var tabSize: Int = 4
    var insertSpaces: Boolean = true
    var splitAttributes: Boolean = false
    var closingTagBracketOnNewLine: Boolean = false
}

Before and After Formatting

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"><TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello" /></LinearLayout>
Implementation: The formatter uses multiple specialized classes:
  • XMLFormatter: Main formatting coordinator
  • DOMElementFormatter: Element formatting logic
  • DOMAttributeFormatter: Attribute alignment
  • DOMTextFormatter: Text content formatting

Advanced Editing Features

Auto-Close Tags

The AdvancedEditProvider handles automatic tag closing:
<!-- Type '<TextView' and '>' -->
<TextView>
    <!-- Automatically inserts closing tag -->
</TextView>

Attribute Quotes

Automatic quote insertion for attribute values:
<!-- Type 'android:text=' -->
android:text=""
<!-- Cursor positioned inside quotes -->

Resource Reference Completion

Type @ to trigger resource reference completion:
  • @string/ - String resources
  • @drawable/ - Drawable resources
  • @color/ - Color resources
  • @dimen/ - Dimension resources
  • @style/ - Style resources
  • @id/ - View IDs
  • @+id/ - Define new ID
  • @android: - Android framework resources

XML Parsing

The XML LSP uses Eclipse LemMinX DOM parser for robust XML parsing:
val document = DOMParser.getInstance().parse(
    contents,
    "http://schemas.android.com/apk/res/android",
    URIResolverExtensionManager()
)
The parser provides:
  • Error Recovery: Continue parsing despite syntax errors
  • Node Location: Accurate position information for completions
  • Namespace Support: Handle android:, app:, and tools: namespaces

Node Type Detection

The completion system detects context using XmlUtils.getNodeType():
enum class NodeType {
    TAG,              // Inside element name: <TextVi|w>
    ATTRIBUTE,        // Inside attribute name: android:lay|
    ATTRIBUTE_VALUE,  // Inside attribute value: android:text="|"
    UNKNOWN          // Cannot determine context
}

Configuration

Server Settings

object XMLServerSettings : IServerSettings {
    override fun completionsEnabled(): Boolean = true
    override fun codeActionsEnabled(): Boolean = true
}

Custom Settings

Apply custom settings to the XML server:
val customSettings = object : IServerSettings {
    override fun completionsEnabled() = true
    override fun codeActionsEnabled() = false
}

xmlServer.applySettings(customSettings)

Performance

Caching

The XML LSP caches parsed documents to improve performance:
  • Parse Cache: Stores DOM trees for recently accessed files
  • Resource Cache: Caches available resources from R class
  • Attribute Cache: Stores attribute definitions for view types

Prefix Matching

Completion is triggered only when a meaningful prefix is typed:
val prefix = XmlUtils.getPrefix(document, cursorPosition, nodeType)
if (prefix.isBlank() && type != ATTRIBUTE_VALUE) {
    return EMPTY  // Don't show completions
}

Limitations

Current limitations of the XML language server:
  • Custom View Attributes: Attributes from custom views may not be suggested unless properly documented
  • Data Binding: Limited completion for data binding expressions inside @{}
  • Constraint Layout: Some ConstraintLayout-specific attributes may have incomplete suggestions
  • Multi-module Resources: Resources from library modules may not always be available

Troubleshooting

Completion Not Working

If XML completion stops working:
  1. Check the file is in a recognized directory (res/layout/, res/drawable/, etc.)
  2. Ensure the XML file has a valid XML declaration
  3. Verify the namespace declarations are correct
  4. Check that the project has been synced

Formatting Issues

If formatting produces unexpected results:
  1. Check for unclosed tags in the XML
  2. Verify the XML is well-formed (balanced tags)
  3. Adjust formatting options in settings

Resource References Not Completing

If @string/ and other resource references don’t complete:
  1. Ensure resources are defined in appropriate XML files
  2. Check that the R class has been generated (build the project)
  3. Verify the module dependencies include the resources

API Reference

XMLLanguageServer

Main server interface:
class XMLLanguageServer : ILanguageServer {
    override val serverId: String = "ide.lsp.xml"
    
    override fun complete(params: CompletionParams?): CompletionResult
    override fun formatCode(params: FormatCodeParams?): CodeFormatResult
    override suspend fun analyze(file: Path): DiagnosticResult
}

XmlCompletionProvider

Completion implementation:
class XmlCompletionProvider(settings: IServerSettings) : ICompletionProvider {
    override fun complete(params: CompletionParams): CompletionResult {
        val document = DOMParser.getInstance().parse(contents, ...)
        val type = XmlUtils.getNodeType(document, cursorPosition)
        val completer = getCompleter(pathData, type)
        return completer.complete(params, pathData, document, type, prefix)
    }
}

CodeFormatProvider

Formatting implementation:
class CodeFormatProvider {
    fun format(params: FormatCodeParams?): CodeFormatResult {
        val formatter = XMLFormatter()
        val edits = formatter.format(document, options)
        return CodeFormatResult(isFormatted = true, edits = edits)
    }
}

Java Support

Learn about Java language features

Kotlin Support

Explore Kotlin language capabilities

Project Management

Manage Android resources and projects

UI Designer

Visual layout editor

Build docs developers (and LLMs) love