Mam zadanie, aby zmienić szerokość i wysokość AlertDialog przez xml, chcę, aby stał się stylem, więc mogę go używać łatwo.I to, muszę zmienić przycisk stylu AlertDialog również.Czy możesz mi powiedzieć sposób osiągnąć target.Thank Ci bardzo wdzięczny. PS lepiej osiągnąć cel poprzez zmianę xml.Android: Jak ustawić szerokość i wysokość AlertDialog oraz przycisk stylu AlertDialog?
7
A
Odpowiedz
18
Istnieją dwa sposoby 1) programowo 2) poprzez zastosowanie układu xml
1)=======>
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
(or)
alertDialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = 150;
lp.height = 500;
lp.x=-170;
lp.y=100;
alertDialog.getWindow().setAttributes(lp);
Jeśli chcesz , aby wyświetlić układ, który będzie wyświetlany, tak jak Alert dialog
, zobacz this
2)========>
choose.xml
<TextView
android:id="@+id/img"
android:layout_width="wrap_content"
android:text="@string/choose"
android:textSize="25dp"
android:textColor="#fff"
android:layout_height="50dp"/>
<TableLayout android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical">
<TableRow
android:id="@+id/tr1"
android:orientation="horizontal"
android:layout_margin="10dp">
<ImageView
android:contentDescription="@string/phone"
android:src="@drawable/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/phnText"
android:layout_width="wrap_content"
android:text="@string/phone"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF000000" />
<TableRow
android:id="@+id/tr2"
android:orientation="horizontal"
android:layout_margin="10dp">
<ImageView
android:contentDescription="@string/sms"
android:src="@drawable/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/smsText"
android:layout_width="wrap_content"
android:text="@string/sms"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
wyświetlacz to jako popup tak jak poniżej
private void showPopUp()
{
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("");
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.choose, null);
helpBuilder.setView(checkboxLayout);
final AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
TableRow tablerowPhone = (TableRow)checkboxLayout.findViewById(R.id.tr1);
TableRow tablerowSms = (TableRow)checkboxLayout.findViewById(R.id.tr2);
tablerowPhone.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
helpDialog.dismiss();
Uri callUri = Uri.parse("tel:" + listview_array[4]);
Intent intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
}
});
tablerowSms.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
helpDialog.dismiss();
Uri smsUri = Uri.parse("sms:" + listview_array[4]);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
startActivity(intent);
}
});
}
wezwanie to showPopUp()
metoda gdzie chcesz. tak, że można ustawić wysokość i szerokość do układu w pliku xml
+0
Dziękuję bardzo. W ten sposób można to zrobić, ale chcę zrobić to przez plik xml. Ponieważ chcę skonfigurować xml do mojego application.do masz sposób zrobić to przez plik xml? Dziękuję raz za razem. – oldfox3721
1
spróbować, to działa na mnie,
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
alertDialog.show();
Powiązane problemy
- 1. Wyłącz domyślnie przycisk AlertDialog
- 2. Przyciski stylu AlertDialog dla aktywności
- 3. Android: Niestandardowe AlertDialog
- 4. Pokazuje Android Wear styl AlertDialog
- 5. Jak odwołać AlertDialog w android
- 6. jak ustawić na tytuł CENTRUM w AlertDialog?
- 7. OnClickListener wewnątrz niestandardowego alertdialog Android
- 8. Android: czcionka o stałej szerokości w AlertDialog
- 9. Android - Custom AlertDialog Kolor tła
- 10. Android AlertDialog tytuł koloru tła
- 11. zrobić mój przycisk styl jak AlertDialog przycisk Styl
- 12. Pierwsze domyślne wypełnienie dla AlertDialog
- 13. AlertDialog Input Text
- 14. Android AlertDialog Przenieś PositiveButton w prawo i NegativeButton po lewej
- 15. jak ustawić wysokość i szerokość nvd3 wykresie
- 16. Zmiana koloru przycisku w AlertDialog
- 17. AlertDialog wewnątrz onClickListener
- 18. Problemy z alertdialog koncert w fragmencie android
- 19. AlertDialog z selektorem
- 20. Wiele obiektów EditText w AlertDialog
- 21. Jak kliknąć "OK" na AlertDialog przez kod?
- 22. Dynamicznie ustawić szerokość i wysokość TextView w systemie Android
- 23. Get AlertDialog tytuł przez findViewById
- 24. jak ustawić detektor onclick dla przycisku obrazu w alertdialog
- 25. Domyślna fokus i klawiatura do EditText w Android AlertDialog
- 26. używając fancybox ustawić wysokość i szerokość
- 27. Jak ustawić tę samą szerokość i wysokość przycisku?
- 28. pokaz świetlny AlertDialog użyciu Theme.Light.NoTitleBar
- 29. Używanie ArrayAdapter z AlertDialog i .setAdapter
- 30. Zmiana rozmiaru czcionki na AlertDialog
Można mieć coś takiego http://stackoverflow.com/questions/1979369/ android-activity-as-a-dialog –
@ userIsAMonkey, dziękuję bardzo, myślałem o użyciu Activity jako o dialogu, ale moim zadaniem jest używać okna dialogowego. ponieważ istnieje wiele dialogów czekających na show. Chcemy mieć styl, który można łatwo pokazać.dziękuję, – oldfox3721