I want to see these buttons but i can't see them because is white. How can i change the colors? - android-studio

AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
builder.setTitle("Sterge Task-ul");
builder.setMessage("Esti sigur ca vrei sa stergi acest Task?");
AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
adapter.deleteItem(position);
}
}).create();
I don't know what to do more, can someone help?

Related

Alert dialog , editText android java

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
TextView titleView = new TextView(this);
EditText editTextView = new EditText(this);
titleView.setText("PASSWORD");
editTextView.setHint("password");
editTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
titleView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
dialogBuilder.setCustomTitle(titleView);
dialogBuilder.setView(editTextView);
dialogBuilder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface DialogInterface, int i) {
String editTextInput = editTextView.getText().toString();
}
});
dialogBuilder.setNegativeButton("dismiss", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
This is my alert dialog . When ,dialog shows, keyboard gets up and editText has focus , i tried to force hidding keyboard different ways but without success so far . I looking forward to show this diakog while keeping keyboard down .

How to prevent alert dialog from appearing when some condition is fulfilled?

//NotificationPermission Dialog
private void notificationPermissionDialog(){
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setCancelable(false)
.setMessage("Do you want to Enable Notifications?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("Yes");
dialogInterface.dismiss();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("No");
dialogInterface.dismiss();
}
}).show();
}
//Save Notification Permission in Preferences
private void savePermissionInPreferences(String isNotificationAllowed){
SharedPreferences sharedPreferences;
sharedPreferences = getContext().getSharedPreferences("PermissionPref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("isNotificationAllowed", isNotificationAllowed);
editor.apply();
}
I have created a dialogue which appears when fragment is opened and ask for permission if I click on NO its value is saved in shared preference for preventing it to appear again but when I replace my fragment in same activity dialogue appears again and again. Please anyone can guide me through it.
Thanks in advance.
So you can do something like below
private void notificationPermissionDialog(){
SharedPreferences sharedPreferences = getSharedPreferences("PermissionPref", Context.MODE_PRIVATE);//Add these
String permission = sharedPreferences.getString("isNotificationAllowed", "");
//Add this line
if(!permission == "No"){
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setCancelable(false)
.setMessage("Do you want to Enable Notifications?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("Yes");
dialogInterface.dismiss();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("No");
dialogInterface.dismiss();
}
}).show();
}
}
//Save Notification Permission in Preferences
private void savePermissionInPreferences(String isNotificationAllowed){
SharedPreferences sharedPreferences;
sharedPreferences = getContext().getSharedPreferences("PermissionPref",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("isNotificationAllowed", isNotificationAllowed);
editor.apply();
}
If the user selected no to the Alert Dialog it wont appear again.

Cannot close a custom AlertDialog

so I have an app with three different buttons(parent buttons) on pressing any of them, the custom alert dialog with 9 different buttons is displayed but the functions of these 9 buttons within the alert dialog are different depending on which of the three parent buttons called it. On pressing any of the 9 buttons, I want the app to perform a particular function and then close the alertdialog. Now the problem is that I can easily call the alert dialog by calling the method showcustomdialog(); that I created but I can't dismiss it using alertdialog.dismiss(); inside the OnClickListener of the parent button since the method has a void result type. I've tried using if-else statements but it doesn't work. How can I achieve what is required?
The method:
private void showCustomDialog() {
ViewGroup viewGroup = findViewById(android.R.id.content);
View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_main2, viewGroup, false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogView);
final AlertDialog alertDialog = builder.create();
alertDialog.show();
}
I am calling the meathod and using it as follows:
parentbutton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showCustomDialog();
alertbutton1.getId();
alertbutton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textView1.setText("500");
function();
//I want to dismiss the alertdialog here.
}
});
alertbutton2.getId();
alertbutton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textView1.setText("1000");
function();
//I want to dismiss the alertdialog here.
}
});
and so on.
I figured out a solution for you using AlertDialog.
parentbutton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createDialog();
}
});
Then the method MUST be a private or public AlertDialog:
private AlertDialog createDialog() {
LayoutInflater inflater = (getActivity()).getLayoutInflater(); // for fragment or getLayoutInflater(); for activity
View v = inflater.inflate(R.layout.dialog_add_new_list, null);
Button okButton = v.findViewById(R.id.confirm_button);
Button cancelButton = v.findViewById(R.id.cancel_button);
final AlertDialog dialog = new AlertDialog.Builder(getActivity()) // for fragment or AlertDialog.Builder ( this ) for activity
.setView(v)
.show();
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View p1) {
dialog.dismiss();
}
});
return dialog;
}
P.S. Replace the ids I used to create this sample with yours.

hello how can i make full width dialog popup in android this is my code

view.findViewById(R.id.doc_prof_det_add_speciality_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
LayoutInflater factory = LayoutInflater.from(v.getContext());
final View view = factory.inflate(R.layout.doc_prof_det_add_speciality, null);
alertDialog.setView(view);
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
});
Try this:
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
//Grab the window of the dialog, and change the width
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = alertDialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
}
});

Android show dialog in Custom View

I create a custom view which showing the simple game
I set the custom view in the MainActivity
setContentView(new CustomView())
In this custom view, only have few ball and the timer
When a ball touch another ball. The timer will stop and show the result.
I don't know how to show the result in a better way. So i tried to create a dialog to show the result.
This code is write in the CustomView class
if (ballIsTouch) {
AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
alertDialog.setTitle("Result");
alertDialog.setMessage(point);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
However, the page is freezed. The dialog haven't show.
create() - is a final step -when you use builder pattern to create dialog u first set in chain all variables and then create dialog - and show so it should be
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
alertDialogBuilder.setTitle("Result");
alertDialogBuilder.setMessage(point);
alertDialogBuilder.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
or
alertDialogBuilder.setTitle("Result")
.setMessage(point)
.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ensure you getContext() is valid (should be activity, service context)**
in activity use this or Myactivity.this in interface/callback in fragment getActivity()
**see Dialog creation context

Resources