Question

I want my GridLayout to have rounded corners like the 3 Buttons do in the below picture. Does this require code that is different for rounding corners of Views such as Buttons, TextViews, etc?

gameplayGL.setBackgroundResource(R.drawable.roundedcorners);
gameplayGL.setBackgroundColor(Color.BLUE);
gameplayGL.getBackground().setAlpha(35);

roundedcorners.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners 
        android:bottomLeftRadius="8dp"
        android:bottomRightRadius="8dp"
        android:topLeftRadius="8dp"
        android:topRightRadius="8dp" />

</shape>

enter image description here

Was it helpful?

Solution

I'm pretty sure calling setBackgroundColor(Color.BLUE) overrides the setBackgroundResource() call.

Try making a different drawable resource that is this

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners 
    android:bottomLeftRadius="8dp"
    android:bottomRightRadius="8dp"
    android:topLeftRadius="8dp"
    android:topRightRadius="8dp" />

<solid
    android:color="#350000FF" />

</shape>

Then setting the background of the gridview to that. You may have to play with the color value to get exactly what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top