Я разрабатываю приложение для Android с несколькими устройствами. Все работают нормально, но для двух вещей. Диалог прогресса и тост, который кажется очень маленьким в Android, но отлично подходит для S2. Может ли кто-нибудь предложить любое обходное решение для того же, чтобы либо увеличить размер тоста, либо прогресс и обязательство. Я уже упоминал поддержку экрана в манифесте, но не использовал.разработать пользовательский progressdialog android
0
A
ответ
1
Вы можете создать собственный тост, где вы можете определить свой собственный макет. проверьте код ниже.
XML макет назван «custom_toast.xml»
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00AAE9"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="@+id/toastImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:src="@drawable/ic_warning" />
<TextView
android:id="@+id/toastText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textColor="#FFFFFF"
android:textSize="7pt"
android:textStyle="italic" />
</LinearLayout>
</LinearLayout>
Ваш класс активности
package com.javatechig.droid.ui;
import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button toastButton = (Button) this.findViewById(R.id.toastButton);
toastButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//create the toast object, set display duration,
Toast.makeText(getApplicationContext(), "This is a plain toast.",
Toast.LENGTH_SHORT).show();
}
});
Button customToastButton = (Button) this.findViewById(R.id.customToastButton);
customToastButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//get the LayoutInflater and inflate the custom_toast layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup)
findViewById(R.id.toast_layout_root));
//get the TextView from the custom_toast layout
TextView text = (TextView) layout.findViewById(R.id.toastText);
text.setText("This is my custom toast");
//create the toast object, set display duration,
//set the view as layout that's inflated above and then call show()
Toast t = new Toast(getApplicationContext());
t.setDuration(Toast.LENGTH_LONG);
t.setView(layout);
t.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Выход ниже
1
Вы можете установить вид для любого типа диалога или тосты, чтобы иметь пользовательский вид. Ниже приведен пример ниже e применяется для диалога Alert или progress.
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate
(R.layout.custom_toast,(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text); text.setText("This is a custom toast");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout); toast.show();
Смежные вопросы
- 1. Пользовательский Drawable для ProgressBar/ProgressDialog
- 2. Как легко разработать пользовательский интерфейс Android?
- 3. Как разработать комплексный пользовательский интерфейс в android
- 4. Почему в ICS мой ProgressDialog не похож на пользовательский ProgressDialog?
- 5. Как настроить Android ProgressDialog?
- 6. Android ProgressDialog
- 7. Позиционирование Custom ProgressDialog Android
- 8. Android custom ProgressDialog Animation
- 9. Пользовательский цвет и фон ProgressDialog
- 10. Как разработать пользовательский указатель транспортира?
- 11. Rails 3 - Разработать: пользовательский маршрут
- 12. Android ProgressDialog отображается неправильно
- 13. Android ProgressDialog style
- 14. Показать ProgressDialog Android
- 15. Android AppCompat ProgressDialog?
- 16. Использование progressDialog в android?
- 17. Android: ProgressDialog не вращается
- 18. Android: Спиннинг ProgressDialog - Как?
- 19. android ProgressDialog - нужен onClickListener?
- 20. Android okhttp Асинхронный progressdialog
- 21. Android: не отображается ProgressDialog
- 22. Android ProgressDialog в AsyncTask
- 23. Появилась тень Android ProgressDialog
- 24. ProgressDialog не отображается - Android
- 25. Определить ProgressDialog в Android
- 26. Проблема с Android ProgressDialog
- 27. Android ProgressDialog с setContentView
- 28. Android ProgressDialog не вращается
- 29. Android ProgressDialog не отображается
- 30. Thread and progressDialog android
Спасибо за ответ, можем ли мы сделать то же самое для progressbar? – bharath