我在点击imageView时创建了一个警告对话框。下面给出了代码:
imgEditStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileActivity.this);
inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.dialog_edit_status, null);
builder.setView(dialogView);
dialog = builder.create();
dialog.show();
final EditText edtStatus = (EditText) dialogView.findViewById(R.id.editStatus);
Button btnOK = (Button) dialogView.findViewById(R.id.btnOK);
// btnOK.getBackground().setColorFilter(getResources().getColor(R.color.orange_color)), PorterDuff.Mode.SRC_ATOP);
btnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Toast.makeText(getApplicationContext(), "OK clicked", Toast.LENGTH_SHORT).show();
String statusText = edtStatus.getText().toString().trim();
new UpdateStatusTask().execute(statusText);
}
});
Button btnCancel = (Button) dialogView.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Cancel clicked", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
}
});
dialog_edit_status.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin20"
android:hint="Enter your status here"
android:paddingBottom="@dimen/padding10"
android:padding="@dimen/padding10"
android:textColor="@color/black_color"
android:textColorHint="@color/gray_color"
android:layout_marginBottom="@dimen/margin10"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin10">
<Button
android:id="@+id/btnOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/margin50"
android:text="OK"
android:background="@color/orange_color"
android:textColor="@color/white_color"/>
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/margin50"
android:text="Cancel"
android:textColor="@color/white_color"/>
</RelativeLayout>
</LinearLayout>
我正在尝试在OK按钮的背景中设置橙色。但是它的大小已经改变了。我尝试使用以下代码:
btnOK.getBackground().setColorFilter(getResources().getColor(R.color.orange_color)), PorterDuff.Mode.SRC_ATOP);
它给了我错误:Drawable中的setColorFilter()无法应用于(int)。请帮我解决问题
答案 0 :(得分:0)
如果您想更改背景颜色但保留其他样式,则下面的内容可能有所帮助。
mails.$
答案 1 :(得分:0)
试试这个:
btnOK.setBackgroundColor(getResources().getColor(R.color.orange_color));
答案 2 :(得分:0)
btnOK.setBackgroundResource(R.color.orange_color);