踩坑記錄 原

####踩坑記錄

2018-10-14 Samsung SM-G9350 Android6.0.1 API23

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

public void onCreate(Bundle savedInstanceState){

        // 提前到這裏不影響其他手機 但是三星的神奇的機器不這樣不行
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        super.onCreate(savedInstanceState);

        // Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
        // Samsung SM-G9350 Android6.0.1 API23
        // 這個明明在setContentView之前了 但是在這個手機上不管用 依然報錯
        // 然後把這行提前到super.onCreate()之前
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        viewGroup = (ViewGroup) View.inflate(this, R.layout.layout_wallet_liveness_recognize, null);
        setContentView(viewGroup);
}                    

        

2018-10-13 想要給某個View設置背景顏色什麼,要參合這xfermode使用,才注意到xfermode是對paint來說的, 也即你想要混合的圖層們得是用的一個paint對象才行. 默認有一個int去記錄顏色,因爲怕int有默認值0所以我給這個變量默認爲-1, 然後發現代碼始終沒法生效,因爲我總是有一行判斷

if(globalColor != -1){
   canvas.drawColor(globalColor);
}

然後好死不死的我在外部調用時賦值是Color.WHITE.

@ColorInt public static final int WHITE       = 0xFFFFFFFF;

這個十六進制的值竟然剛好就是**-1**,oh shit.

2018-10-13


Samsung SM-G9006V Android4.4.2 API 19 發現設置給EditText的一個 line樣式的StateListDrawable無效

1.首先懷疑是不是硬件加速相關影響了. 然後嘗試設置對應EditText的LayoutType -> View.LAYER_TYPE_NONE,iew.LAYER_TYPE_SOFTWARE,iew.LAYER_TYPE_HARDWARE都不好使

2.嘗試通過代碼創建StateListDrawable, 各自設置GradientDrawable 依然無效 GradientDrawable focusTrue = new GradientDrawable(); focusTrue.setShape(GradientDrawable.LINE); focusTrue.setColor(getResources().getColor(R.color.dxm_facepay_font_black)); focusTrue.setStroke(Utils.dp2px(1),0);

    GradientDrawable focusFalse = new GradientDrawable();
    focusFalse.setShape(GradientDrawable.LINE);
    focusFalse.setColor(getResources().getColor(R.color.dxm_facepay_unfocus_line_gray));
    focusFalse.setStroke(Utils.dp2px(0.5F),0);

    int[] focusedState = {android.R.attr.state_focused};
    int[] defaultState = {android.R.attr.state_enabled};

    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(focusedState,focusTrue);
    stateListDrawable.addState(defaultState,focusFalse);
    edittext.setBackground(stateListDrawable);

3.後來嘗試修改原來的實現方式,不用line而用rectangle.解決問題.

這是原先通過畫line的方式 實現的代碼.

<?xml version="1.0" encoding="utf-8"?>

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

<item android:state_focused="true">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
        <solid android:color="@color/dxm_facepay_font_black" />
        <stroke android:width="1dp" />
    </shape>
</item>

<item android:state_focused="false">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
        <solid android:color="@color/dxm_facepay_unfocus_line_gray" />
        <stroke android:width="0.5dp" />
    </shape>
</item>

</selector>

後來改成rectangle但是控制上下間距來實現底部橫線的效果.<shape>標籤默認就是rectangle. 通過一個layer-list來實現,在layer-list中的item們默認就是一個疊加到另一個上面的. 從上到下,默認都是一樣大.如下<item android:bottom="1dp">就讓這個item距離底部1dp. 然後兩個item各自都有顏色,空出來的1dp就變成了一條線的效果.

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

<!-- 所以這麼搞 是因爲發現Samsung SM-G9006V Android4.4.2 API 19  設置line不好使-->

<item android:state_focused="true">
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <solid android:color="@color/dxm_facepay_font_black" />
            </shape>
        </item>

        <item android:bottom="1dp">
            <shape>
                <solid android:color="@color/dxm_facepay_white" />
            </shape>
        </item>
    </layer-list>
</item>

<item android:state_focused="false">
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <solid android:color="@color/dxm_facepay_unfocus_line_gray" />
            </shape>
        </item>

        <item android:bottom="0.5dp">
            <shape>
                <solid android:color="@color/dxm_facepay_white" />
            </shape>
        </item>
    </layer-list>
</item>

</selector>

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