2013-06-06 28 views
0

這是很容易在這樣的XML設置:如何設置使用Java代碼角落的Android

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient android:startColor="#BFEEFF" 
     android:endColor="#40B9FF" 
     android:angle="270"/> 
    <corners 
     android:bottomLeftRadius="6dip" 
     android:bottomRightRadius="6dip"/> 
</shape> 

但我怎麼可以設置它在Java代碼中?

回答

0

我想你想在動態時間創建someView。 (如果這是真的)

我知道,它不是一個正確的答案相對於你的問題,但我會給你一個替代方法來執行這個事情在動態時間,添加形狀文件內選擇器文件並添加選擇器文件在查看的android:drawable =「@ drawable/selector」。

1

通貨膨脹後,它不是一個形狀繪製(我知道這是令人困惑),
而不是它是一個GradientDrawable,代碼是非常簡單的檢查文檔http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html
特別setCornerRadius()。

GradientDrawable mDrawable = new GradientDrawable(); 
mDrawable.setShape(GradientDrawable.RECTANGLE); 
mDrawable.setCornerRadius(5.0f); 
.... 
// (note, this is untested and you might need to set other properties, 
// e.g. color etc.) 
相關問題