文本文字設置 陰影 陰影透明度 陰影模糊度

//TODO 設置陰影 第一個參數是 透明度 第二三個是縱橫陰影長度 第四個顏色值 
 tvContent.setShadowLayer(blur,10,10,Color.parseColor(changeColor(blurColor)));


    //TODO  根據顏色id 轉換解析顏色 目的是將透明度設置進去
    private String changeColor(int id){
        StringBuffer stringBuffer = new StringBuffer();
        int color = id;
        stringBuffer.append("#");
        stringBuffer.append(translateNum(trans));
//        stringBuffer.append(Integer.toHexString(Color.alpha(color)));
        stringBuffer.append(Integer.toHexString(Color.red(color)));
        stringBuffer.append(Integer.toHexString(Color.green(color)));
        stringBuffer.append(Integer.toHexString(Color.blue(color)));
        Log.d("顏色:",stringBuffer.toString());
        return stringBuffer.toString();
//        return stringBuffer.toString().replace("#","#"+translateNum(trans));
    }

    int trans=0;
    //TODO 根據16進制百分比 傳入透明百分比 換算16進制的百分比對應值
    private String translateNum(int trans){
    float temp = 255 * (100-trans) * 1.0f / 100f;
    int alpha = Math.round(temp);
    String hexStr = Integer.toHexString(alpha);
    if (hexStr.length() < 2)
        hexStr = "0" + hexStr;
    System.out.println(trans + "%, " + hexStr.toUpperCase());
    return  hexStr.toUpperCase();
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章