I am trying to use a custom component in my app. This is the code:
Layout file (select_method_layout):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/encabezadometodo"
android:id="#+id/encabezadometodo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"/>
<es.infaplic.aguaics.Componentes.ComponenteSelectMethod
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/methodfile"
android:layout_below="#+id/textexplicacion"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<es.infaplic.aguaics.Componentes.ComponenteSelectMethod
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/methodservice"
android:layout_below="#+id/methodfile"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/layoutmethodservice"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/servicemethod"
android:id="#+id/service"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/layoutmethodfile"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#id/layoutmethodservice">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/filemethod"
android:id="#+id/file"
android:gravity="center"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/textexplicacion"
android:id="#+id/textexplicacion"
android:layout_centerHorizontal="true"
android:layout_below="#+id/encabezadometodo"
android:gravity="center"/>
The class that controls the custom component:
public class ComponenteSelectMethod extends RelativeLayout {
private ImageView imagen;
private TextView text;
public ComponenteSelectMethod(Context context) {
super(context);
inicializar();
}
public ComponenteSelectMethod(Context context, AttributeSet attrs) {
super(context, attrs);
inicializar();
}
private void inicializar() {
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li =
(LayoutInflater)getContext().getSystemService(infService);
li.inflate(R.layout.componente_select_method_layout, this, true);
imagen=(ImageView)findViewById(R.id.imageiconoselectmethod);
text=(TextView)findViewById(R.id.textmethod);
}
public void setImage(int icono){
this.imagen.setBackgroundResource(icono);
}
public void setText(String text){
this.text.setText(text);
}
}
And, in the main class, I am using it this way:
final AlertDialog.Builder dialog=new AlertDialog.Builder(this);
dialog.setTitle(getString(R.string.firsttime));
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.select_method_layout, null);
dialog.setView(dialoglayout);
ComponenteSelectMethod cFile=(ComponenteSelectMethod)dialoglayout.findViewById(R.id.methodfile);
ComponenteSelectMethod cService=(ComponenteSelectMethod)dialoglayout.findViewById(R.id.methodservice);
LinearLayout layoutFile=(LinearLayout)dialoglayout.findViewById(R.id.layoutmethodfile);
LinearLayout layoutService=(LinearLayout)dialoglayout.findViewById(R.id.layoutmethodservice);
cFile.setImage(R.drawable.icono_archivo_agu);
cFile.setText(getString(R.string.textexplicacionfile));
cService.setImage(R.drawable.icono_directorio);
cService.setText(getString(R.string.textexplicacionservice));
final AlertDialog methodDialog=dialog.show();
layoutFile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
settings.edit().putString("method", "file").apply();
methodDialog.dismiss();
proceder();
}
});
layoutService.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
settings.edit().putString("method", "service").apply();
methodDialog.dismiss();
proceder();
}
});
EDIT:
componente_select_method_layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageiconoselectmethod"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:id="#+id/textmethod"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageiconoselectmethod"
android:layout_toEndOf="#+id/imageiconoselectmethod"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"/>
</RelativeLayout>
With this, when I open the xml file, it fails rendering. It stays in "Rendering..." and does nothing more. If I access the Text mode in layout editing, and do anything (like hitting space bar) Android Studio stops responding.
Is something wrong with my custom component? Anybody knows how to avoid Android Studio to hang?
Thank you.
Related
I am developing app having a popup window showing successfully but button inside is not working. When the button is click the event is not listening. The code is shown below.
private void showPopup() {
//LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup_layout,null);
mPopupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
Button btn_popup_submit = (Button)customView.findViewById(R.id.btn_popup_submit);
Button btn_popup_cancel = (Button)customView.findViewById(R.id.btn_popup_cancel);
btn_popup_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "aaa", Toast.LENGTH_SHORT).show();
Log.d("LOG","aaaa");
}
});
btn_popup_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "bbbb", Toast.LENGTH_SHORT).show();
Log.d("LOG","bbbb");
}
});
if(Build.VERSION.SDK_INT>=21){
mPopupWindow.setElevation(5.0f);//5.0f
}
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext, android.R.color.transparent)));
mPopupWindow.setOutsideTouchable(false);
mPopupWindow.setTouchable(false);
mPopupWindow.update();
}
The pop up layout code is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_custom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:background="#5b5e93"
>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Sent."
android:textSize="20sp"
android:textColor="#color/colorWhite"
android:padding="25sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_above="#+id/editText"
android:layout_marginBottom="50dp"
android:background="#color/colorGray"
android:orientation="horizontal"></LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:textSize="16sp"
android:textColor="#color/colorWhite"
android:text="#string/email_sent" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:ems="4"
android:maxLength="4"
android:minLines="4"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btn_popup_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Submit"
android:textAllCaps="false" />
<Button
android:id="#+id/btn_popup_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Cancel"
android:textAllCaps="false" />
</LinearLayout>
</RelativeLayout>
The button names are btn_popup_submit and btn_popup_cancel.
I tried different methods but the problem. I don't know where is the problem facing. Please help me thanks.
Replace this line of code.Allow popWindow Touch.
mPopupWindow.setTouchable(false);
to
mPopupWindow.setTouchable(true);
Popup Library
I have to display my own header in popup and it
here + sign and back arrow is header i want to exactly like this
you can use Costume Dialog like below
public class dialogMesssageType {
Dialog dialog;
Context m_context;
Activity act;
public void showDialog(Activity activity, Context context, final String titre, final String message, final int type) {
dialog = new Dialog(activity);
m_context = context;
act = activity;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog_message_type);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent)));
TextView txt = (TextView) dialog.findViewById(R.id.txt);
TextView titre_id = (TextView) dialog.findViewById(R.id.txt_titre);
TextView ok = (TextView) dialog.findViewById(R.id.confirmation);
ImageView img_type(ImageView)dialog.findViewById(R.id.img_type);
ImageView close = (ImageView) dialog.findViewById(R.id.close);
txt.setText(message);
titre_id.setText(titre);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
xml file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/rounded_gray"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/blue_neigra"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="32dp"
android:id="#+id/img_type"
/>
<TextView
android:id="#+id/txt_titre"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
android:text="Warning"
android:textColor="#039470"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="18dp"
android:gravity="center"
android:text="Please fill in all fields"
android:textColor="#color/white"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp"
android:background="#color/blue_neigra"></View>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:id="#+id/confirmation"
android:textColor="#color/blue_neigra"
android:textSize="20sp"
android:text="Ok"/>
</LinearLayout>
<ImageView
android:id="#+id/close"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:background="#drawable/selector_blue_gray_cercle"
android:padding="12dp"
android:src="#drawable/close_blue" />
</RelativeLayout>
i removed Animation .
How to generate custom dialog box in android like this,
I want just like this.
How to generate it. please give me suggestion.
i have used below code for dialog box, what is the problem in my code?
I have not identify it. please share me any Idea.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video" />
</LinearLayout>
</RelativeLayout>
Please share me any Idea.
Thanks.
Simple, 1st need to create an newcustom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginLeft="55dp"
android:layout_marginRight="55dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="165dp"
android:layout_gravity="center"
android:layout_marginEnd="60dp"
android:layout_marginStart="60dp"
app:cardCornerRadius="8dp"
app:cardElevation="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
android:gravity="center"
android:text="Quit Earning?"
android:textColor="#android:color/black"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. quit Earning?"
android:textSize="18dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmNo"
android:layout_marginRight="45dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="No"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmOk"
android:layout_marginLeft="50dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="Ok"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
</FrameLayout>
Then, in java file (in activity) paste this code
public class ViewDialog {
public void showDialog(Activity activity) {
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.newcustom_layout);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
FrameLayout mDialogNo = dialog.findViewById(R.id.frmNo);
mDialogNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Cancel" ,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
FrameLayout mDialogOk = dialog.findViewById(R.id.frmOk);
mDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Okay" ,Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
dialog.show();
}
}
Finally you can call it wherever you want.
ViewDialog alert = new ViewDialog();
alert.showDialog(CustomDialogActivity.this);
Inside your dailog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
</LinearLayout>
</RelativeLayout>
open dimens.xml and add code mentioned below
<dimen name="thirty_dp">30dp</dimen>
<dimen name="ten_dp">10dp</dimen>
<dimen name="twenty_sp">20sp</dimen>
<dimen name="twenty_dp">20dp</dimen>
<dimen name="sixteen_sp">16sp</dimen>
open drawable and create btn_white.xml add code mentioned blow
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp"></corners>
<solid android:color="#android:color/white"></solid>
</shape>
open mainactivity.java and add the code mentioned below
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.dailog);
dialog.show();
Button declineButton = (Button) dialog.findViewById(R.id.btn_cancel);
// if decline button is clicked, close the custom dialog
declineButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button videoButton = (Button) dialog.findViewById(R.id.btn_video);
// if decline button is clicked, close the custom dialog
videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="#3E80B4"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Do you realy want to exit ?"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#3E80B4"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_yes"
android:layout_width="100dp"
android:layout_height="30dp"
android:background="#android:color/white"
android:clickable="true"
android:text="Yes"
android:textColor="#5DBCD2"
android:textStyle="bold" />
<Button
android:id="#+id/btn_no"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:background="#android:color/white"
android:clickable="true"
android:text="No"
android:textColor="#5DBCD2"
android:textStyle="bold" />
</LinearLayout>
You can change your button by using
android:src=#drawable/image
You have to extends Dialog and implements OnClickListener
public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button yes, no;
public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
yes = (Button) findViewById(R.id.btn_yes);
no = (Button) findViewById(R.id.btn_no);
yes.setOnClickListener(this);
no.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
c.finish();
break;
case R.id.btn_no:
dismiss();
break;
default:
break;
}
dismiss();
}
}
Call Dialog
CustomDialogClass cdd=new CustomDialogClass(Activity.this);
cdd.show();
Maybe try this method
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#color/colorPrimary"
app:cardCornerRadius="16dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_done_all"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorButtonNormal"
android:text="Tebrikler!"
android:layout_gravity="center_horizontal"
android:textSize="36sp"
android:padding="8dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnDialogCancel"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Çıkış"
android:textColor="#FFF"
android:layout_marginRight="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/btnDialogOk"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Devam"
android:textColor="#FFF"
android:layout_marginLeft="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
main.java
Dialog dialog = new Dialog(context, R.style.CustomDialog);
LayoutInflater layoutInflater = LayoutInflater.from(context);
CardView cardView = (CardView) layoutInflater.inflate(R.layout.dialog, null);
dialog.setContentView(cardView);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
dialogBtnCancel();
private void dialogBtnCancel(){
mBtnDialogCancel = dialog.findViewById(R.id.btnDialogCancel);
mBtnDialogOk = dialog.findViewById(R.id.btnDialogOk);
mBtnDialogCancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
mBtnDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
});
}
One of my dialogs has a non-custom title:
NameDialog.java
public class NameDialog extends DialogFragment {
#Override
#NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
return builder.setTitle(R.string.name)
.setView(inflater.inflate(R.layout.name_dialog, null))
.setPositiveButton(R.string.next, null)
.create();
}
}
name_dialog.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/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:ems="10"
android:inputType="textPersonName"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
This is what it looks like:
One of my dialogs has a custom title with the cast icon.
PlayersDialog.java
public class PlayersDialog extends DialogFragment {
#Override
#NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
return builder
.setCustomTitle(inflater.inflate(R.layout.players_title_dialog, null))
.setView(inflater.inflate(R.layout.players_dialog, null))
.setPositiveButton(R.string.start_game, null)
.create();
}
}
players_dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PlayersDialog">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<ListView
android:id="#+id/players"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"/>
</RelativeLayout>
players_title_dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".PlayersDialog">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title"
android:text="#string/players"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="5dp"/>
<android.support.v7.app.MediaRouteButton
android:id="#+id/media_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:mediaRouteTypes="user"
android:visibility="gone"/>
</RelativeLayout>
This is what it looks like:
I just want both dialogs to have consistent formatting.
In your players_title_dialog.xml file replace the players textView with the following
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title"
android:text="#string/players"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#3db6e3"
android:layout_marginLeft="10dp"/>
And may be the font size could be decreased by 1dp and padding could be added 3px in you list
There is quite strange and bad error on devices from sony family.
I have implemented actually the same code as it was in example.
There is a problem with dialog layout which show very very strange behaviour.
So far I don't know how to fix it.
Here is the picture:
Here is my code:
public class DialogFragmentRadioChannelAdd extends DialogFragment {
private DialogInterface.OnClickListener listener;
private AddChannelListener addChannelListener;
public DialogFragmentRadioChannelAdd() {
setDialogType(DialogType.AlertDialog);
}
#Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = LayoutInflater.from(getActivity());
View dialoglayout = inflater.inflate(R.layout.add_channel, null);
final EditText channelAddTitle = (EditText) dialoglayout.findViewById(R.id.addChannelTitle);
final EditText channelAddUrl = (EditText) dialoglayout.findViewById(R.id.addChannelUrl);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(("Dodaj kanał radiowy"));
builder.setView(dialoglayout);
builder.setPositiveButton("Zapisz", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (addChannelListener != null)
addChannelListener.onSave(dialogInterface, i, channelAddTitle, channelAddUrl);
}
})
.setNegativeButton("Anuluj", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (addChannelListener != null)
addChannelListener.onCancel(dialogInterface, i);
}
});
return builder.create();
}
public void setAddChannelListener(AddChannelListener addChannelListener)
{
this.addChannelListener = addChannelListener;
}
}
And here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<org.holoeverywhere.widget.LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="1dp"
android:layout_margin="1dp"
>
<org.holoeverywhere.widget.EditText
android:id="#+id/addChannelTitle"
android:minWidth="250dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="Wpisz tytuł kanału radiowego"/>
<org.holoeverywhere.widget.EditText
android:id="#+id/addChannelUrl"
android:layout_below="#id/addChannelTitle"
android:minWidth="250dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="Wpisz adres url kanału radiowego"/>
</org.holoeverywhere.widget.LinearLayout>
Someone was talking to replace linearlayout with something else in root but I don't have so much experience to find out the solution. As I said the problem is usualy with sony family in android 2.3.+
Edit:
So I spend some time to find out any hack.
Here is a link to show what did I changed (hosted on diff comparator 1year)(or the right comparing to original code on the left) Link to compartor with changes.
What I did is just changing linear layout into relative in base holoeverywhere layout called alert_dialog_holo.xml found in holoeverywhere library in res/layout
Fixed alert_dialog.xml layout for version holoeverywhere (dont know but today is 22-12-2013 so I think it is 2.1.0)
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_height="wrap_content"
android:id="#+id/parentPanel"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/topPanel"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="2dip"
android:id="#+id/titleDividerTop"
android:background="#color/holo_blue_light"
android:visibility="gone" />
<LinearLayout
android:layout_below="#+id/titleDividerTop"
android:layout_width="match_parent"
android:layout_marginRight="16dip"
android:layout_marginLeft="16dip"
android:gravity="center_vertical|left"
android:minHeight="#dimen/alert_dialog_title_height"
android:layout_height="wrap_content"
android:id="#+id/title_template"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:paddingRight="8dip"
android:layout_height="wrap_content"
android:id="#+id/icon"
android:contentDescription="#string/loading"></ImageView>
<Internal.DialogTitle
android:layout_width="match_parent"
style="?android:windowTitleStyle"
android:ellipsize="end"
android:singleLine="true"
android:layout_height="wrap_content"
android:id="#+id/alertTitle"></Internal.DialogTitle>
</LinearLayout>
<View
android:layout_below="#+id/title_template"
android:layout_width="match_parent"
android:layout_height="2dip"
android:id="#+id/titleDivider"
android:background="?alertDialogTitleDividerColor"
android:visibility="gone"></View>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contentPanel"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:clipToPadding="false"
android:layout_height="wrap_content"
android:id="#+id/scrollView">
<TextView
android:layout_width="match_parent"
style="?android:attr/textAppearanceMedium"
android:paddingBottom="8dip"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:layout_height="wrap_content"
android:paddingTop="8dip"
android:id="#+id/message" />
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/customPanel">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/custom"></FrameLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:minHeight="#dimen/alert_dialog_button_bar_height"
android:layout_height="wrap_content"
android:id="#+id/buttonPanel"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/buttonPanelTopDivivder"
android:background="?dividerHorizontal" />
<LinearLayout
android:layout_width="match_parent"
style="?buttonBarStyle"
android:measureWithLargestChild="true"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_gravity="left"
style="?buttonBarButtonStyle"
android:minHeight="#dimen/alert_dialog_button_bar_height"
android:textSize="14sp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/button2"
android:maxLines="2"></Button>
<Button
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
style="?buttonBarButtonStyle"
android:minHeight="#dimen/alert_dialog_button_bar_height"
android:textSize="14sp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/button3"
android:maxLines="2"></Button>
<Button
android:layout_width="wrap_content"
android:layout_gravity="right"
style="?buttonBarButtonStyle"
android:minHeight="#dimen/alert_dialog_button_bar_height"
android:textSize="14sp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/button1"
android:maxLines="2"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
You will get some errors in library's code but you need just to change it to relative where is linear
I am talking about class AlertController.java also stored in holoeverywhere libary in /src/widget/.
For listview/singlechoicemenu in dialog and according to up xml you need change some code in AlertController in method setupContent(xxx)
private void setupContent(RelativeLayout contentPanel) {
mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
mScrollView.setFocusable(false);
mMessageView = (TextView) mWindow.findViewById(R.id.message);
if (mMessageView == null) {
return;
}
if (mMessage != null) {
mMessageView.setText(mMessage);
} else {
mMessageView.setVisibility(View.GONE);
mScrollView.removeView(mMessageView);
if (mListView != null) {
contentPanel.removeView(mWindow.findViewById(R.id.scrollView));
contentPanel.addView(mListView, new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
contentPanel.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
} else {
contentPanel.setVisibility(View.GONE);
}
}
}