具有透明背景失败的 PNG 图像的运行时 ImageButton
runtime ImageButton with PNG image with transparent background failure
我想在每次按下 ADD 按钮(见红色圆圈)时添加,使用 2 个 Edittext 和 1 个 ImageButton 创建运行时 ROW,我使用 PNG 图像,但是当我尝试创建透明背景时结果是或灰色图像或白色图像(见黄色箭头)...
当
这是添加行的运行时代码
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();
}
});
这是第 ROWXML
<?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
如果我使用 android:background 这就是结果
如果我远程处理代码,结果是:
我将此代码用于“添加”按钮并且工作正常
android:background="#00000000"
我用这个参数编译:
compileSdkVersion 25
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.bandweb.myviewrecipes"
minSdkVersion 16
targetSdkVersion 23
在您的 ImageView 中,您必须使用 android:src
而不是 app:srcCompat
,所以:
改变这个:
app:srcCompat="@drawable/directory_up"
有了这个:
android:src="@drawable/directory_up"
我想在每次按下 ADD 按钮(见红色圆圈)时添加,使用 2 个 Edittext 和 1 个 ImageButton 创建运行时 ROW,我使用 PNG 图像,但是当我尝试创建透明背景时结果是或灰色图像或白色图像(见黄色箭头)...
当
这是添加行的运行时代码
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();
}
});
这是第 ROWXML
<?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
如果我使用 android:background 这就是结果
如果我远程处理代码,结果是:
我将此代码用于“添加”按钮并且工作正常 android:background="#00000000"
我用这个参数编译:
compileSdkVersion 25
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.bandweb.myviewrecipes"
minSdkVersion 16
targetSdkVersion 23
在您的 ImageView 中,您必须使用 android:src
而不是 app:srcCompat
,所以:
改变这个:
app:srcCompat="@drawable/directory_up"
有了这个:
android:src="@drawable/directory_up"