Android - Way to appear bordered text on the TextView?

Is there a way to appear bordered text on the TextView ?

Asked by: Melissa689 | Posted: 24-01-2022

Answer 1

I would suggest to extend TextView
See Android Custom Component Guide


package samples.test;
public class MyTextView extends TextView {
    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

    public MyTextView(Context context) {

    protected void onDraw(Canvas canvas) {
        Rect rect = new Rect();
        Paint paint = new Paint();
        canvas.drawRect(rect, paint);       

Than use it in layout xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" android:layout_width="fill_parent"
    <samples.test.MyTextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />

Answered by: Kellan827 | Posted: 25-02-2022

Answer 2

Most simple way is use a 9 patch background.

<TextView android:id="@+id/txt_target"
            android:layout_marginRight="5dip" />

Answered by: Lucas557 | Posted: 25-02-2022

Similar questions

user interface - Android MapView + Tab example

i need to have an mapview on a tab. The attached example shows how to do this if using intents. Now i want to change the zoom level of the mapview(s). How can i do this, although i'm using intents (or is there completely different solution)? Activity code: public class TabMapsExample extends TabActivity { ...

user interface - Make Android Activity looks like dialog

I am trying to open a dialog on widget click. I have solved the problem skinning the activity started on click with android:theme="@android:style/Theme.Dialog". Unfortunately I cannot reach the same look of a dialog. This is the outcome: Dialog from widget Instead, I would like to reach this result (except for ...

user interface - Android Center Layout Hiding Button

I am working on a fairly basic screen layout for my first Android application and running into some issues. My goal is to have a TextView in the top left and top right corner, a large "hello world" TextView in the exact middle of the screen, and then a button at the bottom of the screen. My issue is, to center the "hello world" TextView vertically, I need to set the layout_height="fill_parent". However, this causes the ...

user interface - Android - Adjust screen when keyboard pops up?

I want to be able to adjust my UI screen on Android when the soft keyboard pops up. So at the minute I have something similiar to the first picture below where I have and EditText at the bottom of the screen and when a user taps the EditText I want the same as what happens in the second picture. That is that the EditText gets moved up and appears to "sit" on top of the soft keyboard, when the soft keyboard ...

How do I use the opengl interface in Android ndk

If I want to use the opengl interface in android ndk, then will it be possible to show me a simple tutorial to let me master the android ndk? I just wanna know how to operate in android ndk first.

user interface - Android - how do I display a list of items in an HTML-like Ordered list?

Still new to Android I want to display some data as an HTML-like ordered list (non-actionable). Example; Item One Item Two Item Three I feel I am missing something obvious. Thanks, JD

java - How to obtain MAC address of WiFi network interface?

It seems the implementation of android does not have a byte[] getHardwareAddress() method I've found several forums of people trying to do this with no definitive answer, I need to get a somewhat cross-device UUID, s...

user interface - Android Radial / Pie Menu

I am looking to create a radial menu in a game that I am writing. Is there a class or API included to assist with this or an open source solution? Something like this. Thank you, Jake

java - How to make an Advanced user interface in Android?

i wonder how you can make an advanced Android User interface where you can add for example a drag drop and more graphics options? is that by using OpenGl ?! this is example of UI in iPhone Apps. example 1

user interface - Text with gradient in Android

How would I extend TextView to allow the drawing of text with a gradient effect?

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android