我上點擊一個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按鈕的背景中設置橙色,但其尺寸發生了變化。我試着用下面的代碼:在繪製對象setColorFilter()不能適用於(INT):
btnOK.getBackground().setColorFilter(getResources().getColor(R.color.orange_color)), PorterDuff.Mode.SRC_ATOP);
它給我的錯誤。請幫我解決問題
btnOK.setBackgroundColor(getResources()。getColor(R.color.your_color));使用此 –
同樣的問題。增加了按鈕的大小。 –
查看我的回答下面 –