簡體   English   中英

android句柄選擇器狀態

[英]android handle selector state

我正在使用以下代碼將圖像從內存加載到選項卡圖標。 圖像已針對state_enabled正確加載,但選擇state_select時未更改。 我做錯了嗎? 謝謝。

ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);

        File imgFile = new  File("data/data/"+PACKAGE_NAME+"/biblioteca/" + imageName);
        File imgFileSel = new  File("data/data/"+PACKAGE_NAME+"/biblioteca/" + imageName);

        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        Drawable d = new BitmapDrawable(myBitmap);

        Bitmap myBitmapSelected = BitmapFactory.decodeFile(imgFileSel.getAbsolutePath());
        Drawable dSel = new BitmapDrawable(myBitmapSelected);

        StateListDrawable selector = new StateListDrawable();
        selector.addState(new int[]{ android.R.attr.state_enabled }, d);
        selector.addState(new int[]{ android.R.attr.state_selected }, dSel);
        icon.setImageDrawable(selector);}

xml發出警報“缺少內容描述”

<ImageView android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/icon"

    /> 

state_pressed幫助您...

missing content description  

ant只是Lint錯誤檢查而已....它沒有不同,

StateListDrawable selector = new StateListDrawable();
selector.addState(new int[]{ android.R.attr.state_pressed }, dSel);
selector.addState(new int[]{ android.R.attr.state_focussed }, dSel);
selector.addState(new int[]{ android.R.attr.state_enabled }, d);
selector.addState(new int[]{ android.R.attr.state_selected }, dSel);
icon.setImageDrawable(selector);

嘗試也參考此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM