An android shape line is an XML drawable resource in res/drawable/ that defines borders, dividers and backgrounds using rectangles, ovals or lines. Add a stroke element to set border width and colour, then assign the file to any view’s android:background attribute for pixel-perfect EditText borders and spinner backgrounds without any Java or Kotlin code.
- Shape drawables are the standard Android way to add borders to EditText and TextView widgets, no third-party library needed.
- Custom spinner backgrounds with a dropdown arrow require a
layer-listdrawable that combines a shape border with an arrow image. - Gradient backgrounds use a
gradientchild element inside a shape drawable, withstartColor,centerColorandendColorattributes. - The xxhdpi density bucket targets screens at 480 dpi and requires 144 x 144 px launcher icons, while xxxhdpi targets 640 dpi and requires 192 x 192 px.
- Sectioned ListViews are built using a custom adapter that returns different view types for section headers and data rows.
How Android Shape Drawables Power EditText and TextView Borders
Every Android view accepts a drawable as its background. A shape drawable is an XML file that describes a geometric shape, and the stroke tag inside it becomes a visible border. Using an android shape line drawable is the cleanest way to create an android edittext with border because it scales perfectly across every screen density without bitmap assets.
Create a file called res/drawable/edittext_border.xml. The root element is <shape android:shape="rectangle">. Inside it, add <stroke android:width="1dp" android:color="#CCCCCC" /> for the border and <corners android:radius="8dp" /> for rounded corners. Assign it with android:background="@drawable/edittext_border" on the EditText in your layout XML.
EditText Border vs TextView Border: What Changes
The drawable file is identical for both widgets. The difference is intent. An EditText border signals “this is an input field”, so designers usually pair it with padding of at least 12dp and a hint text colour that contrasts well. A textview border is more decorative, often used for tags, labels or card outlines.
Google’s Material Design 3 guidelines recommend a minimum touch target of 48 x 48 dp for any interactive element, which means your bordered EditText should never be shorter than 48dp in height. Keeping this rule prevents accessibility failures that can hurt your app’s Play Store rating.
Solid Fill, Transparent Fill and Padding
Add a <solid android:color="#FFFFFF" /> element inside the shape to give the field a white background. Leave it out for a transparent fill. Always add android:padding="12dp" directly on the EditText so the typed text doesn’t collide with the border stroke. Small details like this separate polished apps from rough ones.
Custom Spinner Backgrounds and the Arrow Problem
The default Android spinner looks different on every device because each manufacturer styles it differently. Setting a spinner background android custom drawable gives you a consistent look across Samsung, OnePlus, Realme and every other OEM popular in India, where Android holds approximately 95% smartphone market share according to StatCounter’s Global Stats report for 2024.
The trick is a layer-list drawable. The first layer is your shape with a border stroke, giving you the box. The second layer is an <item android:drawable="@drawable/ic_dropdown_arrow" android:gravity="end|center_vertical" /> that places an arrow icon on the right side. Set this layer-list as the spinner’s background and you’ve got a proper spinner background with arrow android in about 20 lines of XML.
Suppressing the Default Spinner Divider
Set android:background="@null" first if you’re inheriting a theme that adds its own underline or box. Then apply your custom layer-list. Skipping this step causes a double-border effect that’s especially visible on devices running Android 12 and above, where the default Material You spinner has its own pronounced stroke.
Android Gradient Backgrounds in Shape Drawables
Replace the <solid> element with a <gradient> element to create an android gradient background. Set android:type="linear", android:startColor="#4A90E2" and android:endColor="#7B4FE9" for a blue-to-purple sweep. Add android:angle="135" to run it diagonally. This works on any view including spinner backgrounds, card containers and sectioned list headers.
Gradients are hardware-accelerated on Android, so there’s no performance penalty for using them on RecyclerView item backgrounds, even in lists with hundreds of rows. According to the Android developer documentation published by Google, hardware acceleration has been enabled by default since Android 3.0 (API level 11). This means every android shape line gradient you define renders on the GPU without extra configuration.
Density Buckets, xxhdpi and Icon Sizes That Actually Matter
Android groups physical screens into density buckets so a single APK can serve phones with wildly different pixel densities. The system picks the closest matching resource folder and scales up or down from there. Getting this wrong means blurry icons on high-end phones or oversized assets that inflate your APK unnecessarily.
The term xxhdpi stands for extra-extra-high dots per inch, which maps to approximately 480 dpi. Phones in this bucket include most mid-range and flagship devices sold in India today, including popular Redmi, Realme and Samsung Galaxy M-series models. The xxhdpi full form is simply “extra extra high density”.
The Complete Android Icon Size Table
| Density Bucket | DPI Range | Launcher Icon (px) | Action Bar Icon (px) | Notification Icon (px) |
|---|---|---|---|---|
| mdpi | ~160 dpi | 48 x 48 | 24 x 24 | 24 x 24 |
| hdpi | ~240 dpi | 72 x 72 | 36 x 36 | 36 x 36 |
| xhdpi | ~320 dpi | 96 x 96 | 48 x 48 | 48 x 48 |
| xxhdpi | ~480 dpi | 144 x 144 | 72 x 72 | 72 x 72 |
| xxxhdpi | ~640 dpi | 192 x 192 | 96 x 96 | 96 x 96 |
The xxhdpi icon size for a launcher icon is 144 x 144 px. The xxxhdpi icon size is 192 x 192 px. These figures come directly from the Android developer documentation under the “Support different pixel densities” guide, last revised by Google in 2024. Always export all five sizes from your design tool before submitting an APK, because the Google Play Console will warn you if launcher icon assets are missing for any required density bucket.
Sectioned ListViews and the android shape line Divider Pattern
A sectioned ListView uses a custom adapter that overrides getViewTypeCount() to return 2 and getItemViewType() to flag each position as either a header or a data row. The header rows inflate a separate layout that carries its own android shape line drawable as a bottom divider, making the section boundary visually obvious without any extra view padding.
For a listview background image, set android:background="@drawable/your_image" on the ListView element and also set android:cacheColorHint="#00000000" to prevent the scroll cache from painting a black rectangle over your image during fast scrolling. This is a subtle bug that trips up many developers building their first data-heavy screen.
Android development is one of the top skills every college student should learn before graduation because India’s mobile app market reached 28 billion app downloads in 2023 according to data.ai’s State of Mobile 2024 report, second only to China globally. Knowing how to build polished UIs using techniques like the android shape line drawable is what separates a portfolio project from a deployable product.
If you’re exploring which direction to take your programming skills, the guide on how to choose the right career path after graduation covers mobile development alongside cloud, cybersecurity and AI as high-growth options for 2026. The best career options in 2026 for students and professionals also ranks Android development solidly in the top ten by starting salary in India.
Putting It All Together: Your Action Plan This Week
Start with a single EditText in a new Android Studio project. Write the shape drawable XML, apply it, run it on an emulator set to xxhdpi density and check that the border renders crisply. Then duplicate the drawable, swap the stroke for a gradient, and apply it to a Spinner with a layer-list arrow. You’ll have covered the core android shape line techniques in under two hours.
Export your launcher icon at all five density sizes using Android Studio’s Image Asset tool (File, New, Image Asset). Check the preview at each density before generating. Commit everything to version control before touching the manifest. These three habits alone cut the most common UI submission errors on the Play Console.
For structured learning beyond these snippets, the top online courses for high-salary jobs list includes Android and mobile development paths with verified instructor credentials. Students on a budget should check the best free online learning platforms for students in 2025 before spending anything. And if you’re just entering the job market, the overview of entry-level jobs for teens and graduates shows which Android skills employers actually test in first-round interviews.
If you want to go beyond UI and build a complete, industry-ready skill set, 3.0 University’s certification courses in Cybersecurity, Ethical Hacking, AI, Blockchain and Web3 are designed for students, working professionals and career switchers who need practical credentials, not just theory. The curriculum is built around real tools and real job requirements, which matters when recruiters at Indian tech firms screen hundreds of resumes for the same role.
Frequently Asked Questions
How do you add a border to an EditText in Android?
Create a shape drawable XML file in res/drawable/ with a <shape android:shape="rectangle"> root, a <stroke> element for border width and colour, and optional <corners> for rounding. Set this drawable as the EditText’s android:background attribute in your layout XML. Add at least 12dp padding on the EditText so text doesn’t overlap the border.
How do you set a custom spinner background?
Use a layer-list drawable. The first layer is a shape with a stroke border. The second layer is your dropdown arrow image positioned with android:gravity="end|center_vertical". Assign the layer-list to android:background on the Spinner widget. Set android:background="@null" first if your theme adds its own default styling that would conflict.
What icon size does xxhdpi require?
The xxhdpi density bucket requires a 144 x 144 px launcher icon, a 72 x 72 px action bar icon and a 72 x 72 px notification icon. These figures are defined in Google’s official Android developer documentation. Always generate assets for all five buckets (mdpi through xxxhdpi) so the system picks the sharpest match for every device.
What does xxhdpi mean in Android?
xxhdpi stands for extra-extra-high dots per inch, representing approximately 480 dpi screen density. It’s one of six standard Android density buckets: ldpi, mdpi, hdpi, xhdpi, xxhdpi and xxxhdpi. Most mid-range and flagship smartphones sold in India today fall into the xxhdpi or xxxhdpi bucket, making these the most important densities to test on.
How do you add a gradient background in Android?
Inside a shape drawable XML, replace the <solid> element with a <gradient> element. Set android:type="linear", define android:startColor and android:endColor, and use android:angle (in multiples of 45) to control direction. Apply the drawable to any view’s android:background attribute. Android hardware-accelerates gradient rendering by default from API level 11 onwards, as documented by Google in the Android developer guides.
Last updated: September 2026. Reviewed by the 3University editorial team.