2016-12-29 3 views
-4

Ich versuche, ein Dialogfeld mit Textview in Android zu erstellen wie:Wie erstelle ich einen Dialog mit Textansicht in Android?

Image]

Für die Textview Erstellen ich object.settype(textviewobject) folgende Funktion verwenden aber es gibt keinen Erfolg.

+0

einen benutzerdefinierten Dialog erstellen: https://www.mkyong.com/android/android-custom-dialog-example/ –

+0

Sie die Warnung Dialog class.http durch die Verlängerung der DialogFragment anpassen: // v4all123 .blogspot.in/2013/09/custom-dialogfragmnet-beispiel-in-android.html –

+0

was ist ihre anforderung –

Antwort

0

Nutzung erhalten diese: -

private void fn_showAlertDialog() { 
     new AlertDialog.Builder(YourActivity.this) 
      .setTitle("Title of your dialog") 
      .setMessage("Text that you want to show.") 
      .setCancelable(false) 
      .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        //do your task 
        dialog.cancel(); 
       } 
      }) 
      .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        //do your task 
        dialog.cancel(); 
       } 
      }) 
      .setIcon(android.R.drawable.ic_dialog_alert) 
      .show(); 
} 
0

Verwenden wie dieser Alertdialog, und ein anderes Layout für Dialog erstellen:

final AlertDialog.Builder builder = new AlertDialog.Builder(context); 
       LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       @SuppressLint("InflateParams") final View alertlayout = inflater.inflate(R.layout.notif_msg_dialog, null); 

       TextView text_main=(TextView)alertlayout.findViewById(R.id.notif_msg); 
       text_main.setText("YOUR TEXT"); 


       builder.setView(alertlayout); 
       packsizeDialog=builder.create(); 
       packsizeDialog.show(); 

Hier ist notif_msg_dialog.xml Layout, das Textview

0
  final Dialog dialog = new Dialog(this); 
      dialog.setContentView(R.layout.dialog); 
      TextView text1 = 
         (TextView)dialog.findViewById(R.id.text1); 
      Button proceed = 
      (Button)dialog.findViewById(R.id.button); 

      proceed.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        dialog.dismiss(); 

       } 
      }); 

      dialog.show(); 

dialog.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/text1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Text1" 
    android:layout_centerInParent="true"/> 

    <Button 
    android:id="@+id/button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Proceed" 
    android:layout_alignParentBottom="true"/> 


</RelativeLayout> 
hat

Ich hoffe, das hilft

0

Nur AlertDialog.Builder verwenden und setzen Sie Ihren Text in setMessage wird es angezeigt

 AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 
     builder.setMessage("your text"); 
     builder.create(); 
     builder.show(); 
0

Sie können Hilfe von folgenden Beitrag http://stackoverflow.com/questions/10903754/input-text-dialog-android

0

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> 

</LinearLayout> 

Sie müssen sich Dialog und Geräte 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(); 
    } 
} 

Wie dies nennen?

CustomDialogClass cdd = new CustomDialogClass(MainActivity.this); 
cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
cdd.show(); 
Verwandte Themen