2017-01-15 74 views
0

我想添加每次我按ADD按鈕(見紅色圓圈)創建一個運行時ROW與2 Edittext和1 ImageButton,我使用PNG圖像,但是當我嘗試創建一個透明背景結果是或灰度圖像或白色圖像(見黃色箭頭)...運行時ImageButton與透明背景故障的PNG圖像

這是添加ROW運行時代碼

ImgBtAdd.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

       LayoutInflater layoutInflater = (LayoutInflater) appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       final View addView = layoutInflater.inflate(R.layout.rrow_ing, null); 

       AutoCompleteTextView et_ing = (AutoCompleteTextView) addView.findViewById(R.id.et_ingrediente); 
       EditText et_qty = (EditText) addView.findViewById(R.id.et_qty); 
       et_ing.setAdapter(adapter); 
       //textOut.setText(et_ing.getText().toString()); 
       final ImageButton ImgBtClear = (ImageButton) addView.findViewById(R.id.imgBt_clear); 

       //ImgBtClear.setBackgroundColor(Color.TRANSPARENT); //don't work 
       //ImgBtClear.setBackgroundResource(0);    //don't work 

       ImgBtClear.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         ((LinearLayout)addView.getParent()).removeView(addView); 
         listAllAddView(); 
        } 
       }); 

       //ImgBtClear.setOnClickListener(thisListener); 
       IngContainer.addView(addView); 
       listAllAddView(); 
      } 
     }); 

這是ROW

的XML
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

     <android.support.design.widget.TextInputLayout 
      android:id="@+id/input_name" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/input_qty" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true"> 

      <AutoCompleteTextView 
       android:id="@+id/et_ingrediente" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/txt_ingrediene" 
       android:text="" 
       android:inputType="text" 
       app:errorEnabled="true"/> 
     </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/input_qty" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@+id/imgBt_clear" 
     android:layout_toStartOf="@+id/imgBt_clear" 
     > 
     <android.support.design.widget.TextInputEditText 
      android:id="@+id/et_qty" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/txt_quantita" 
      android:text="" 
      android:inputType="number|numberDecimal" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/input_qty" 
      android:layout_toEndOf="@+id/input_qty"/> 
    </android.support.design.widget.TextInputLayout> 

    <ImageButton 
     android:id="@+id/imgBt_clear" 
     android:layout_width="60dp" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/directory_up" 
     android:scaleType="centerInside" 
     tools:ignore="ContentDescription" 
     android:focusable="false" 
     android:layout_alignParentRight="true" 
     android:baselineAlignBottom="true" 
     android:layout_alignBottom="@+id/input_qty" 

     android:background="#00000000" //don't work 
     android:background="@null" //don't work 
     android:background="@android:color/transparent" //don't work 

     android:layout_alignParentTop="true"/> 
</RelativeLayout> 

我已經嘗試了不同的方法:

android:background="#00000000" //don't work 
android:background="@null" //don't work 
android:background="@android:color/transparent" //don't work 

enter image description here

如果我使用機器人:背景這是結果 如果我remothe代碼中的結果: enter image description here

我用這個代碼作爲ADD按鈕並且工作正常 的android:背景= 「#00000000」

我用這個參數編譯:

compileSdkVersion 25 
    buildToolsVersion "23.0.3" 
    defaultConfig { 
     applicationId "com.bandweb.myviewrecipes" 
     minSdkVersion 16 
     targetSdkVersion 23 

回答

1

在您的ImageView您必須使用android:srcapp:srcCompat,所以:

更改此:

app:srcCompat="@drawable/directory_up" 

有了這個:

android:src="@drawable/directory_up"