15148

Android dialog background with corner radius has layered background

Question:

I'm new to Android, and really Java also. In my app, I've got an alert dialog I'm throwing up that displays a date and time picker for the user to select a datetime they would like to send a message. That part is going fine.

In my xml, when I set a background attribute, which is currently blue and has a corner radius, there is seemingly an additional white background without a corner radius peeking out behind it. I'm a little miffed. Any help is appreciated.

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="@drawable/corners_qk" android:layout_width="match_parent" android:padding="8dp" android:layout_height="match_parent"> <DatePicker android:id="@+id/date_picker" android:layout_width="match_parent" android:calendarViewShown="true" android:spinnersShown="false" android:layout_weight="4" android:layout_height="0dp" /> <TimePicker android:id="@+id/time_picker" android:layout_weight="4" android:layout_width="match_parent" android:layout_height="0dp" /> <Button android:id="@+id/date_time_set" android:layout_weight="1" android:layout_width="match_parent" android:background="@drawable/corners" android:text="@string/picker_button" android:layout_height="0dp" /> </LinearLayout>

corners_qk.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dp" /> <solid android:color="@color/qkblue"/> </shape>

colors.xml:

<resources> <color name="red">#FF0000</color> <color name="qkblue">#2483d0</color> </resources>

java:

final View dialogView = View.inflate(this, R.layout.date_time_picker, null); final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); dialogView.findViewById(R.id.date_time_set).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.date_picker); TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker); Calendar calendar = new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), timePicker.getCurrentHour(), timePicker.getCurrentMinute()); long time = calendar.getTimeInMillis(); try { messageSend(); } catch (JSONException | IOException e) { e.printStackTrace(); } }}); alertDialog.setView(dialogView); alertDialog.show();

Answer1:

Actually the the background that you are seeing is the default theme of the AlertDialog which is Light_THEME, There is no way to make it transparent instead of using the AlertDialog just use the Dialog where you can make the its theme transparent.

<strong>example:</strong>

final Dialog alertDialog = new Dialog(this); alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); alertDialog.setContentView(R.layout.date_time_picker); alertDialog.findViewById(R.id.date_time_set).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DatePicker datePicker = (DatePicker) alertDialog.findViewById(R.id.date_picker); TimePicker timePicker = (TimePicker) alertDialog.findViewById(R.id.time_picker); Calendar calendar = new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), timePicker.getCurrentHour(), timePicker.getCurrentMinute()); long time = calendar.getTimeInMillis(); }}); alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); alertDialog.show();

<strong>result:</strong>

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/KYl96.png" data-original="https://i.stack.imgur.com/KYl96.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Recommend

  • I can't show LinearLayout at bottom to scroll view
  • adMob | Extend Banner size?
  • Can I override some attribute of drawable shape?
  • Sticky Footer Below ListView in Android Layout
  • Overlapping ImageView in RelativeView
  • Android custom dialog linearlayout size same as dialogs bg image
  • Android : Strike out Text with bold or thicker line than default STRIKE_THRU_TEXT_FLAG
  • Background image crashes android
  • Change Design Support Navigation View Header Title Programmatically
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • Android Custom dialog inflating from layout - alignment issue
  • EditText ignores the ImeActionLabel
  • Toolbar shifts up, when soft keyboard appears
  • Gray line inside cardview :)?
  • write text on image and show it to a imageview
  • Unable to resolve Static method?
  • is it possible to insert a line break in this tooltip?
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Seeking advice on Jetty HttpClient Hang
  • does jqgrid support a multiple checkbox list for editing
  • Why is an OPTIONS request sent to the server?
  • Pass value from viewmodel to script in zk
  • Insert into database using onclick function
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Optimizing database types to compact database (SQLite)
  • How do I fake an specific browser client when using Java's Net library?
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Do I've to free mysql result after storing it?
  • QuartzCore.framework for Mono Develop
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?