下面列出了android.widget.Toast#makeText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
if (menu == null) {
return super.onMenuOpened(featureId, null);
}
if (!SignalStore.uiHints().hasSeenGroupSettingsMenuToast()) {
MenuItem settingsMenuItem = menu.findItem(R.id.menu_group_settings);
if (settingsMenuItem != null && settingsMenuItem.isVisible()) {
Toast toast = Toast.makeText(this, R.string.ConversationActivity__more_options_now_in_group_settings, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
SignalStore.uiHints().markHasSeenGroupSettingsMenuToast();
}
}
return super.onMenuOpened(featureId, menu);
}
public void ShowToast(String text)
{
if (!TextUtils.isEmpty(text))
{
try
{
if (mToast == null)
{
mToast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
}
else
{
mToast.setText(text);
}
mToast.show();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
/**
* Updates the view associated to the activity after the finish of an operation trying to copy a
* file.
*
* @param operation Copy operation performed.
* @param result Result of the copy operation.
*/
private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
refreshListOfFilesFragment();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(FileDisplayActivity.this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
msg.show();
} catch (NotFoundException e) {
Log_OC.e(TAG, "Error while trying to show fail message ", e);
}
}
}
public static void showToast(Context context, String message, int duration, int gravity, int xOffset, int yOffset) {
if (message == null){
return;
}
if (sToast == null) {
sToast = Toast.makeText(context, "", duration);
} else {
sToast.cancel();
sToast = Toast.makeText(context, "", duration);
}
sToast.setText(message);
sToast.setDuration(duration);
sToast.setGravity(gravity, xOffset, yOffset);
sToast.show();
}
/**
* Starts taking a picture countdown with playing an audio
* and showing a text countdown for defined interval, and then takes a picture.
*/
private void startTakePicCounter() {
playAudioPresenter.setInternalPathForPlay(InternalPaths.TAKING_PHOTO_AUDIO);
playAudioPresenter.start();
@SuppressLint("ShowToast") final Toast toast = Toast.makeText(MBApp.getApp().getApplicationContext(), "bbb", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
//Toast.LENGTH_SHORT will keep the toast for 2s, our interval is 1s and calling toast.show()
//after 1s will cause some count to be missed. Only call toast.show() just before 2s interval.
//Also add delay to show the "Ready" toast.
new CountDownTimer(Constants.PIC_COUNTER_DURATION_MILLIS, Constants.PIC_COUNTER_INTERVAL_MILLIS) {
public void onTick(long millisUntilFinished) {
int count = (int) millisUntilFinished / Constants.PIC_COUNTER_INTERVAL_MILLIS;
toast.setText("Ready in... " + count);
if(count % 2 != 0)
toast.show();
}
public void onFinish() {
toast.setText("Ready");
toast.show();
mButtonClick.postDelayed(new Runnable() {
@Override
public void run() {
mButtonClick.callOnClick();
}
}, 200);
}
}.start();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_word_selection);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
AssetManager assetManager = getAssets();
try {
InputStream inputStream = assetManager.open("words.txt");
dictionary = new PathDictionary(inputStream);
} catch (IOException e) {
Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
toast.show();
}
}
/**
* process back pressed
*/
@Override
public void onBackPressed() {
// process back for fragment
if (processBackPressed()) {
return;
}
// process back for fragment
boolean enableBackPressed = true;
if (mCurrentFragment != null) {
enableBackPressed = !mCurrentFragment.processBackPressed();
}
if (enableBackPressed) {
int cnt = getSupportFragmentManager().getBackStackEntryCount();
if (cnt <= 1 && isTaskRoot()) {
String closeWarningHint = getCloseWarning();
if (!mCloseWarned && !TextUtils.isEmpty(closeWarningHint)) {
Toast toast = Toast.makeText(this, closeWarningHint, Toast.LENGTH_SHORT);
toast.show();
mCloseWarned = true;
} else {
doReturnBack();
}
} else {
mCloseWarned = false;
doReturnBack();
}
}
}
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();
}
public static Toast showToast(Context context, int i) {
if (mContext == context) {
mToast.setText(i);
} else {
mContext = context;
mToast = Toast.makeText(context, i, Toast.LENGTH_SHORT);
}
mToast.show();
return mToast;
}
public static void show(Context context,CharSequence character,int duration){
if(toast==null){
toast=Toast.makeText(context,character,duration);
}else {
toast.setText(character);
toast.setDuration(duration);
}
toast.show();
}
/**
* 长时间显示Toast
*
* @param context
* @param message
*/
public static void showLong(Context context, int message) {
if (null == toast) {
toast = Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_LONG);
// toast.setGravity(Gravity.CENTER, 0, 0);
} else {
toast.setText(message);
}
toast.show();
}
@Override
public void onHeaderClick(AdapterView<?> parent, View view, long id) {
String text = "Header " + ((TextView)view.findViewById(android.R.id.text1)).getText() + " was tapped.";
if (mToast == null) {
mToast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
} else {
mToast.setText(text);
}
mToast.show();
}
@Override
public void showStockAlreadyExist() {
Toast toast = Toast.makeText(this, getResources().getString(R.string.stocks_already_exist),
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, Gravity.CENTER, 0);
toast.show();
}
private void listing13_26() {
// Listing 13-26: Displaying a Toast
Context context = this;
String msg = "To health and happiness!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, msg, duration);
// Remember, you must *always* call show()
toast.show();
}
@Override
public void onSliderClick(BaseSliderView coreSlider) {
Toast.makeText(this, "Clicked Item", Toast.LENGTH_SHORT);
}
private void init(){
TapDetector tapDetector = new TapDetector(mPaint, this, colMan);
mDetector = new GestureDetector(mContext, tapDetector);
Toast toast = Toast.makeText(mContext, "You may double tap, move or resize info window", Toast.LENGTH_LONG);
toast.show();
}
@OnClick(R.id.go)
public void go() {
Editable url = urlView.getText();
if (TextUtils.isEmpty(url)) {
Toast.makeText(this, "url is empty", Toast.LENGTH_SHORT);
return;
}
RxEasyHttp.get(url.toString(), new RxEasyStringConverter())
.doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(@NonNull Subscription subscription) throws Exception {
dialog.show();
body.setText("");
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new FlowableSubscriber<String>() {
@Override
public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
dialog.show();
body.setText("");
}
@Override
public void onNext(String response) {
body.setText(response);
}
@Override
public void onError(Throwable t) {
body.setText(t.toString());
}
@Override
public void onComplete() {
dialog.cancel();
}
});
}
public void tellJoke(View view) {
Context context = this;
CharSequence text = this.getString(R.string.toast_text);
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
/**
* Make a standard {@link Boast} that just contains a text view with the
* text from a resource.
*
* @param context The context to use. Usually your {@link android.app.Application}
* or {@link android.app.Activity} object.
* @param resId The resource id of the string resource to use. Can be formatted
* text.
* @param duration How long to display the message. Either {@link //LENGTH_SHORT} or
* {@link //LENGTH_LONG}
* @throws Resources.NotFoundException if the resource can't be found.
*/
@SuppressLint("ShowToast")
public static Boast makeText(Context context, int resId, int duration)
throws Resources.NotFoundException {
return new Boast(Toast.makeText(context, resId, duration));
}
/**
* Creat a Toast object with given message
* @param msg Toast message
* @return A Toast object
*/
private Toast makeToast(String msg) {
return Toast.makeText(getView().getAppContext(), msg, Toast.LENGTH_SHORT);
}