本文整理匯總了Java中android.widget.Toast.makeText方法的典型用法代碼示例。如果您正苦於以下問題:Java Toast.makeText方法的具體用法?Java Toast.makeText怎麽用?Java Toast.makeText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.Toast
的用法示例。
在下文中一共展示了Toast.makeText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: show
import android.widget.Toast; //導入方法依賴的package包/類
/**
* Show a toast.
*
* @param text The text to show.
* @param durationLong Whether the toast show for a long period of time?
* @param mode The display mode to use. Either {@link Mode#NORMAL} or {@link Mode#REPLACEABLE}
*/
public static void show(CharSequence text, boolean durationLong, Mode mode) {
final int duration = durationLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
if (mode != Mode.REPLACEABLE) {
Toast.makeText(sContext, text, duration).show();
return;
}
if (sToast == null || sDuration != duration) {
sDuration = duration;
sToast = Toast.makeText(sContext, text, duration);
} else {
try {
sToast.setText(text);
} catch (RuntimeException e) {
sToast = Toast.makeText(sContext, text, duration);
}
}
sToast.show();
}
示例2: show
import android.widget.Toast; //導入方法依賴的package包/類
public static void show(Context context, String msg, boolean isLong, int gravity) {
if (context == null || msg == null) {
return;
}
if (toast == null) { // Create Toast firstly.
toast = Toast.makeText(context.getApplicationContext(), msg,
isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
defGravity = toast.getGravity();
offsetX = toast.getXOffset();
offsetY = toast.getYOffset();
} else {
toast.setDuration(isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
toast.setText(msg);
}
if (gravity == -1) {
toast.setGravity(defGravity, offsetX, offsetY);
} else {
toast.setGravity(gravity, 0, 0);
}
toast.show();
}
示例3: showLongCustomToast
import android.widget.Toast; //導入方法依賴的package包/類
@SuppressLint("ShowToast")
public static void showLongCustomToast(final Context context, final String text) {
if (Looper.myLooper() == Looper.getMainLooper()) {
if (toast == null) {
toast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG);
}
toast.setText(text);
toast.show();
} else {
HandlerUtils.getHandler().post(new Runnable() {
@Override
public void run() {
if (toast == null) {
toast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG);
}
toast.setText(text);
toast.show();
}
});
}
}
示例4: onClick
import android.widget.Toast; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
//switch (v.getId()) {
if (v.getId() == GoogleSignInButton){
//case GoogleSignInButton: {
if(isNetworkAvailable(this)) {
signIn();
} else {
Toast toast = Toast.makeText(getApplicationContext(),
getResources().getString(R.string.network_unavailable_toast), Toast.LENGTH_SHORT);
toast.show();
}
//break;
//}
}
else if (v.getId() == SkipSignInButton) {
Intent intent = new Intent(SignInActivity.this, MainActivity.class);
startActivity(intent);
}
}
示例5: checkconnection
import android.widget.Toast; //導入方法依賴的package包/類
public void checkconnection()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = cm
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo datac = cm
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if ((wifi != null & datac != null)
&& (wifi.isConnected() | datac.isConnected())) {
//connection is avlilable
}else{
//no connection
Toast toast = Toast.makeText(MainActivity.this, "No Internet Connection Please make Internet for Contine",
Toast.LENGTH_SHORT);
toast.show();
}
}
示例6: show
import android.widget.Toast; //導入方法依賴的package包/類
public static void show(String text) {
if (toast == null) {
toast = Toast.makeText(MyApplication.getInstance(), "", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
}
toast.setText(text);
toast.show();
}
示例7: showToast
import android.widget.Toast; //導入方法依賴的package包/類
/**
* 顯示吐司
*
* @param text 文本
* @param duration 顯示時長
*/
private static void showToast(CharSequence text, int duration) {
if (isJumpWhenMore) cancelToast();
if (sToast == null) {
sToast = Toast.makeText(Utils.getContext(), text, duration);
} else {
sToast.setText(text);
sToast.setDuration(duration);
}
sToast.show();
}
示例8: single
import android.widget.Toast; //導入方法依賴的package包/類
/**
* 彈出多個toast時, 不會一個一個的彈, 後麵一個要顯示的內容直接顯示在當前的toast上
*/
public static void single(Context context,String msg) {
if (toast == null) {
toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
示例9: showToast
import android.widget.Toast; //導入方法依賴的package包/類
private void showToast(String p_strMessage) {
if (m_jToast == null) {
m_jToast = Toast.makeText(m_jContext, "", Toast.LENGTH_SHORT);
}
m_jToast.setText(p_strMessage);
m_jToast.show();
}
示例10: setToastPosition
import android.widget.Toast; //導入方法依賴的package包/類
public static Toast setToastPosition(Context context, String string ,int grivity,int xOffset, int yOffset){
if (context == null)
return null;
if(toast == null){
toast = Toast.makeText(context,string,Toast.LENGTH_SHORT);
}else{
toast.setText(string);
}
toast.setGravity(grivity,xOffset, yOffset);
return toast;
}
示例11: showToast
import android.widget.Toast; //導入方法依賴的package包/類
public void showToast(CharSequence msg) {
Activity activity = getActivity();
if (activity != null) {
if (toast == null) toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
toast.setText(msg);
toast.show();
}
}
示例12: showPasteMessage
import android.widget.Toast; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private void showPasteMessage(String label) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
return;
}
final Toast toast = Toast.makeText(webView.getContext(), label, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
示例13: showToast
import android.widget.Toast; //導入方法依賴的package包/類
private void showToast(int resid) {
if (mToast == null) {
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
}
mToast.setText(resid);
mToast.show();
}
示例14: showToast
import android.widget.Toast; //導入方法依賴的package包/類
public void showToast(int resId) {
String text = getResources().getString(resId);
if (mToast == null) {
mToast = Toast.makeText(MessageActivity.this, text, Toast.LENGTH_SHORT);
} else {
mToast.setText(text);
mToast.setDuration(Toast.LENGTH_SHORT);
}
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.show();
}
示例15: displayShortToast
import android.widget.Toast; //導入方法依賴的package包/類
public void displayShortToast(Context context,String msg){
if(context == null){
return;
}
if(mToast == null){
mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
}
mToast.setText(msg);
mToast.show();
}