Android Gradient on Lollipop not working. - API 21

后端 未结 5 1878
终归单人心
终归单人心 2020-12-09 20:16

When I try to use Gradient on Lollipop, it doesnt work. While it works on all previous versions.

Here is my example:



        
相关标签:
5条回答
  • 2020-12-09 20:44
    int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < Build.VERSION_CODES.LOLLIPOP) {
            //in your gradient use android:gradientRadius="500"
        } else {
          // in your gradient use android:gradientRadius="80%p" or 
          // android:gradientRadius="200dp"
    

    Try write two different xml files using different gradientRadius style

    0 讨论(0)
  • 2020-12-09 20:51

    Seems I found another workaround - set gradient background in code:

    findViewById(R.id.bg).setBackground(ContextCompat.getDrawable(context,R.drawable.bg_gradient));
    
    0 讨论(0)
  • It is a bug. Check this here: https://code.google.com/p/android/issues/detail?id=77862

    enter image description here

    0 讨论(0)
  • 2020-12-09 20:54

    I had the same problem and created 2 different files:

    in drawables

    android:gradientRadius="270"
    

    and in drawables-v21

    android:gradientRadius="270dp"
    

    Now it works fine.

    0 讨论(0)
  • 2020-12-09 20:54

    use like this will be fine:

    android:gradientRadius="50%p"
    
    0 讨论(0)
提交回复
热议问题