1. Download our Official Android App: Forums for Android!

Apps round corners of a textVeiw?

Discussion in 'Android Development' started by frenchsquared, Sep 29, 2011.

  1. frenchsquared

    frenchsquared Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    7
    Joined:
    Sep 26, 2011

    Sep 26, 2011
    7
    0
    25
    I figured out how to do this:
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="#FFFFFF"/>
    <corners
    android:bottomRightRadius="15dp"
    android:bottomLeftRadius="15dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp"/>
    </shape>

    but that isnt quite correct.

    I have a few functions that changes the textView based on what is happening.

    public void goingUp(String DATA) {
    final TextView tvAction = (TextView) findViewById(R.id.tvAction);
    tvAction.setBackgroundColor(Color.rgb(151, 192, 36));
    tvAction.setText(DATA);
    tvAction.setTextColor(Color.rgb(71, 82, 41));
    //tvAction.setBackgroundDrawable(R.drawable.tvactionup);
    }

    I want to dynamically change that to use the xml drawable
    OR
    dynamically round the corners.

    Help Please...
     

    Advertisement

  2. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    The commented out line is how you programmatically change the background drawable, however application resources cannot contain spaces in their names. If a particular resource does include a space, not only will it bark about that, but any lines of code referencing that resource will be deemed incorrect.

    With that said, it is much easier to create a xml drawable detailing the various states of the view and then make the view use that xml as its background drawable, whether that be done in an XML layout file, or hard coded.
     

Share This Page

Loading...