android - Transparent background on custom Dialog -
i'm trying transparent backgroud on custon dialog, can't done on android 4.4.4. works on android 5.1.
the result i'm looking this: http://www.americocarelli.com.br/android_5.1.png
but this:http://www.americocarelli.com.br/android_4.4.4.png
this custom layout:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialogo_layout_root" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/transparente" android:windowbackground="@color/transparente"> <textview android:id="@+id/titulo_dialogo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:gravity="center_horizontal" android:paddingstart="@dimen/paddingstartend" android:paddingend="@dimen/paddingstartend" android:paddingtop="@dimen/paddingtopbottom" android:paddingbottom="@dimen/paddingtopbottom" android:background="@color/fundoescuro" android:textsize="@dimen/abc_text_size_title_material_toolbar"/> <imageview android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/drawer_shadow_down" android:layout_below="@id/titulo_dialogo" android:contentdescription="@string/..."/> <textview android:id="@+id/mensagem_dialogo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/titulo_dialogo" android:paddingstart="@dimen/paddingstartend" android:paddingend="@dimen/paddingstartend" android:paddingtop="8dp" android:paddingbottom="@dimen/paddingtopbottom" android:background="@color/transparente"/> <tablelayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/mensagem_dialogo" android:layout_alignparentstart="true" android:shrinkcolumns="*" android:stretchcolumns="*"> <tablerow> <button android:id="@+id/botaonegativo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_shape" android:textallcaps="false"/> <button android:id="@+id/botaopositivo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_shape" android:textallcaps="false"/> </tablerow> </tablelayout> </relativelayout>
on style.xml, got definition:
<color name="transparente">#00ffffff</color>
and code:
public class dialogos extends dialogfragment { private static final string parametro_titulo = "titulo"; private static final string parametro_mensagem = "mensagem"; private static final string parametro_txt_btn_positivo = "txtbtnpositivo"; private static final string parametro_txt_btn_negativo = "txtbtnnegativo"; public dialogos(){ } public static dialogos newinstance(int titulo, int mensagem, int txtbtnpositivo, int txtbtnnegativo) { dialogos fragment = new dialogos(); bundle args = new bundle(); args.putint(parametro_titulo, titulo); args.putint(parametro_mensagem, mensagem); args.putint(parametro_txt_btn_positivo, txtbtnpositivo); args.putint(parametro_txt_btn_negativo, txtbtnnegativo); fragment.setarguments(args); return fragment; } @override public dialog oncreatedialog(bundle savedinstancestate) { int titulo = getarguments().getint(parametro_titulo); int mensagem = getarguments().getint(parametro_mensagem); int txtbtnpositivo = getarguments().getint(parametro_txt_btn_positivo); int txtbtnnegativo = getarguments().getint(parametro_txt_btn_negativo); typeface fonte = typeface.createfromasset(getactivity().getassets(), "fonts/regencielightalt.ttf"); final alertdialog.builder builder = new alertdialog.builder(getactivity()); layoutinflater inflater = getactivity().getlayoutinflater(); view view = inflater.inflate(r.layout.mensagem_dialogo, null); textview tvtitulo = (textview) view.findviewbyid(r.id.titulo_dialogo); textview tvmensagem = (textview) view.findviewbyid(r.id.mensagem_dialogo); tvtitulo.settypeface(fonte); tvmensagem.settypeface(fonte); if (titulo != 0) tvtitulo.settext(titulo); button btnpositivo = (button) view.findviewbyid(r.id.botaopositivo); button btnnegativo = (button) view.findviewbyid(r.id.botaonegativo); tvmensagem.settext(mensagem); btnpositivo.settypeface(fonte); btnnegativo.settypeface(fonte); btnpositivo.settext(txtbtnpositivo); btnnegativo.settext(txtbtnnegativo); btnpositivo.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { gettargetfragment().onactivityresult(gettargetrequestcode(), activity.result_ok, getactivity().getintent()); } }); btnnegativo.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { gettargetfragment().onactivityresult(gettargetrequestcode(), activity.result_canceled, getactivity().getintent()); } }); builder.setview(view); return builder.create(); } }
the problem alertdialog builder not designing transparent dialog , , have black background theme it, instead use dialog create transparent theme instead.
sample:
dialog alertdialog = new dialog(this); alertdialog.requestwindowfeature(window.feature_no_title); alertdialog.setcontentview(r.layout.tabs); alertdialog.getwindow().setbackgrounddrawable(new colordrawable(android.graphics.color.transparent)); alertdialog.show();
using dialog not require theme manipulation transparent background easy.
Comments
Post a Comment