I want to create dialog with adMob , but it always gives an error , that its not enough place to put it . so is it possible to make dialog width equal to screen width ?
here is how i create it all :
public void CreateDialog(){
Dialog d = new Dialog(this);
d.setTitle("Loading...");
LinearLayout ll = new LinearLayout(d.getContext());
ll.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
ll.addView(adView);
d.setContentView(ll);
d.show();
}
// AdView is loading normally , and working without dialog;
Related
I am trying to show a showcase inside my bottomsheetdialog, as shown in my code below:
MainActivity.java:
report.setOnClickListener(v -> {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.bottom_dialog_layout);
EditText report_bill_type = dialog.findViewById(R.id.bll);
dialog.show();
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable((Color.TRANSPARENT)));
dialog.getWindow().setGravity(Gravity.BOTTOM);
new GuideView.Builder(v.getContext())
.setTitle("Title here")
.setContentText("Description here")
.setGravity(smartdevelop.ir.eram.showcaseviewlib.config.Gravity.auto)
.setTargetView(report_bill_type) //showcase keeps showing behind the dialog
.setDismissType(DismissType.anywhere)
.build()
.show();
});
When I execute the code, the showcase keeps showing behind the dialog. How do I resolve this issue?
I am using this showcase view.
I have a Fragment that does the following:
showProgressBar();
controller.calc();
setTextResult();
hiddenProgressBar();
My showProgressBar:
ProgressBar loadingCalc = new ProgressBar(requireContext(), null, android.R.attr.progressBarStyle);
loadingCalc.setId(View.generateViewId());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
loadingCalc.setLayoutParams(layoutParams);
alertDialog = new AlertDialog.Builder(requireContext(), R.style.Dialog)
.setView(loadingCalc)
.setCancelable(false)
.create();
alertDialog.show();
My hiddenProgressBar:
if (alertDialog != null) {
alertDialog.dismiss();
}
First the Fragment executes the showProgressBar, leaving the AlertDialog visible. Then it calculates and in the end executes the hiddenProgressBar. Visually it doesn't. When I run the application it first performs the calculation and at the end it shows the AlertDialogand quickly withdraws it.
What the code is doing:
Calculate > showing the AlertDialog> hiding the AlertDialog
What should happen:
Show AlertDialog > Calculate > Hide AlertDialog
Observation: I've already tried using DialogFragment but it has the same behavior as AlertDialog. I just want a Dialog with a ProgressBar while Android does a calculation that can take a while.
How can I solve this?
// Custom Dialog Box
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this, R.style.Theme_AppCompat_Dialog_Alert);
final View mView = getLayoutInflater().inflate(R.layout.completed, null);
ImageButton imgForm = (ImageButton) mView.findViewById(R.id.RateButton);
mBuilder.setCancelable(false);
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show(); // Dialogbox appears
// Interest Rating
final AlertDialog.Builder nBuilder = new AlertDialog.Builder( MainActivity.this, R.style.Theme_AppCompat_Light_Dialog_Alert);
final View nView = getLayoutInflater().inflate(R.layout.intrst, null);
Save_Intrst = (Button) nView.findViewById(R.id.SaveIntrst);
nBuilder.setCancelable(false);
nBuilder.setView(nView);
final AlertDialog dilog = nBuilder.create();
// LongPress Image Button
imgForm.setOnLongClickListener(new View.OnLongClickListener(){
#Override
public boolean onLongClick(View view){
dialog.dismiss();
dilog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dilog.show(); // Dialogbox appears
return true;
}
});
Save_Intrst.setOnClickListener(new View.OnClickListener(){
String IntrstLvl;
#Override
public void onClick(View v){
RatingBar rBar = (RatingBar)nView.findViewById(R.id.ratingStar);
IntrstLvl = Integer.toString(rBar.getNumStars());
addData(IntrstLvl);
dilog.dismiss();
Log.d(TAG,"Dismissed");
}
});
Whenever I select "save" within the Save_Intrst it saves 5 stars regardless of what I choose. I'm still fairly new to Android development and have been java coding for a bit now.
This is just a snippet of code of the project and I believe it will be enough, it shows my submit button, the submit button will launch a dialog box that will have a secret button in an image (ImgForm) the image doesn't show but that's not the problem, after long pressing it will launch another dialog that has a 5 Star Rating Bar and a Save button, this is used for rating after the person completes the previous requirements. The rating will always save "5" regardless of what was inserted, even after a reinstall of app onto the device.
getNumStars() will tell you the maximum number of stars shown and will always be 5 as you have defined it. If you want the actual selected rating, you will need getRating(). See this documentation.
You need to use the rBar.getRating()
RatingBar rBar = (RatingBar)nView.findViewById(R.id.ratingStar);
IntrstLvl = Integer.toString(rBar.getRating());
https://developer.android.com/reference/android/widget/RatingBar.html
You are calling getNumStars() which according to the documentation "Returns the number of stars shown." which means the total number of stars a user can select. You should instead be checking getRating() which returns the number of stars currently selected.
https://developer.android.com/reference/android/widget/RatingBar.html#getRating()
I have a surface (which extends SurfaceView), an AdView and now I want to add a WebView, which I'm going to need to position dynamically.
For start, I'm trying to add my web view at the center and make its size the device's width and half its height. I'm with a 800X480 device and landscape mode, so for now I want to set its border at left=0, top=120, right=800, bottom=360, just for the sake of testing. Later on I'll want to be able to set it dynamically, but so far this doesn't even work:
private MySurface surface;
private AdView adView;
private WebView
.
.
.
// create the ad view
adView = new AdView(this, AdSize.SMART_BANNER, AD_MOB_ID);
adView.setAdListener(new MyAdListener());
// create the surface
surface = MySurface.getRef(this);
// set a listener for touch event
surface.setOnTouchListener(this);
// create the web view
webView = new WebView(this);
webView.setWebViewClient(new WebViewClient());
webView.setVisibility(View.GONE);
LayoutParams webViewParams = new LayoutParams(800,240); // this works
webViewParams.setMargins(0, 120, 800, 360); // this does nothing...
// create a relative layout
RelativeLayout l = new RelativeLayout(this);
// add the surface
l.addView(surface);
// add the ad view at the bottom
AdView.LayoutParams adViewParams = new AdView.LayoutParams(
AdView.LayoutParams.WRAP_CONTENT,
AdView.LayoutParams.WRAP_CONTENT);
adViewParams.addRule(AdView.ALIGN_PARENT_BOTTOM);
l.addView(adView, adViewParams);
l.addView(webView, webViewParams);
setContentView(l);
// load an ad
//loadAdMob();
when I later set the webview visibility to visible:
webView.loadUrl(url);
webView.setVisibility(View.VISIBLE);
It appears the right width and height but starts at the very top of the screen :(
Can anyone help ? Thanks.
Ok, I think I got it:
webView = new WebView(this);
webView.setWebViewClient(new WebViewClient());
RelativeLayout.LayoutParams webViewParams= new RelativeLayout.LayoutParams(800, 240);
webViewParams.addRule(RelativeLayout.CENTER_IN_PARENT);
RelativeLayout l = new RelativeLayout(this);
l.addView(surface);
l.addView(adView, adViewParams);
l.addView(webView, webViewParams);
setContentView(l);
credit goes here
I have some Android code, where I'm using Dialog class to display
public void createCustomDialog(String msg)
{
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Error");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(msg);
ImageView img = (ImageView) dialog.findViewById(R.id.image);
img.setImageResource(android.R.drawable.ic_dialog_alert);
dialog.show();
}
Can anyone help me with the corresponding Blackberry code for it
You can use the BlackBerry Dialog class to do this.
You would use this:
Dialog.alert(String message);
as follows:
Dialog.alert.("This is a Dialog!");
Output (In a Dialog Box):
This is a Dialog!
To add Image Please see :
http://www.javaquery.com/2011/07/how-to-put-image-in-dialog-box.html