toast

Android - Confirm app exit with toast

人盡茶涼 提交于 2019-11-27 01:41:12
问题 I'm new to Android development and I want it so when the user presses the back button on the main activity, a toast message appears with a "confirm exit by pressing the back button again" message. How would I do this? This is what I have so far: @Override public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); Toast s = Toast.makeText(getBaseContext(), "Press back again to exit", Toast.LENGTH_LONG); s.show(); wait(); public boolean onBackPressed() { finish(); }

Android: How to set the colour of a Toast's text

谁说我不能喝 提交于 2019-11-27 00:20:14
问题 I am displaying a toast message as the result of an if statement using the following code: Toast.makeText(getBaseContext(), "Please Enter Price", Toast.LENGTH_SHORT).show(); It is displayed as white text on a white background, as such it can not be read! My question is, how can I change the colour of the toast's text? 回答1: You can create a custom Toast view to suit your requirements. See the section titled "Creating a Custom Toast View" at http://developer.android.com/guide/topics/ui

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare();

只谈情不闲聊 提交于 2019-11-27 00:01:05
问题 I have an Android app running a thread. I want a Toast message to show with a message. When I do this, I get the below exception: Logcat trace: FATAL EXCEPTION: Timer-0 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.<init>(Handler.java:121) at android.widget.Toast$TN.<init>(Toast.java:322) at android.widget.Toast.<init>(Toast.java:91) at android.widget.Toast.makeText(Toast.java:238) Is there a work around for pushing

I am trying to display a toast when this button is pressed. But the code is not working

↘锁芯ラ 提交于 2019-11-26 23:30:31
问题 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText text = (EditText)findViewById(R.id.editText1); EditText text1 = (EditText)findViewById(R.id.editText2); String userid = text.getText().toString(); String pass =

Can I cancel previous Toast when I want to show an other Toast?

☆樱花仙子☆ 提交于 2019-11-26 23:00:25
问题 In my app, I construct a calendar widget for my activity, when I scroll it to previous or next month, I let it make a toast and show it. The question is, the toast need time to show, when I scroll it fast enough, for example, I scrolled to "2012/05" and "2012/06" and scroll to "2012/07" without pause, I have to wait the Toast of "2012/05", "2012/06","2012/07" to show one by one slowly. Seems like Android has an invisible queue to manage toasts how can I clean it and only show the last toast?

Can't create handler inside thread that has not called Looper.prepare()

主宰稳场 提交于 2019-11-26 22:19:39
问题: Can't create handler inside thread that has not called Looper.prepare() 1,在报错的方法前加Looper.prepare(); 方法末尾加Looper.loop(); 2,问题原因: 在android的多线程开发中,比如asyncTask,在其doInBackground()方法,调用了更新UI的方法。 解决办法: 把更新UI的操作,放到消息处理器中处理;在doInBackground()方法中发送更新消息: Handler updateDate = new Handler(){ @Override public void handleMessage(Message msg) { switch(msg.what){ case LOADING_FINISHED: listView.setAdapter(gameAdapter); break; } } }; 3, Toast和Looper。Handler消息循环机制。 (1) Looper类别用来为一个线程开启一个消息循环。默认情况下Android中新诞生的线程是没有开启消息循环的。(主线程除外,主线程系统会自动为其创建Looper对象,开启消息循环) Looper对象通过MessageQueue来存放消息和事件。一个线程只能有一个Looper

Android 报错:can't create handler inside thread that has not called looper.prepare() toast

岁酱吖の 提交于 2019-11-26 22:19:20
错误原因:在线程中更新UI! 不要在子线程中更新UI!不要在子线程中更新UI!不要在子线程中更新UI! 重要的事情说三遍!!! 错误代码如下: public class SendThread implements Runnable{ @Override public void run() { // TODO Auto-generated method stub try{ sock.getOutputStream().write(new SendOver(P[6],P[7],P[8],P[9]).getbuf()); Toast.makeText(getApplicationContext(), "I am sending", Toast.LENGTH_SHORT).show(); //此句应该删掉 sock.close(); }catch(IOException e){ e.printStackTrace(); } } } 应该要把Toast 这个函数放在Handler中解决。 来源: http://www.cnblogs.com/lws520/p/6434447.html

How to stop displaying message from Toast when Application is closed?

最后都变了- 提交于 2019-11-26 20:41:37
问题 This is my sample code: public class MainActivity extends Activity { Button buttonClick; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonClick = (Button) findViewById(R.id.buttonClick); buttonClick.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "Here is the Toast", Toast.LENGTH_SHORT).show(); }

Android cancel Toast when exiting the app and when toast is being shown

☆樱花仙子☆ 提交于 2019-11-26 20:25:16
I have read about this kind of problem here but the answers don't seem to be working. I show a Toast when user clicks a button. When the user continously clicks the button the toast keeps on being displayed again and again even when the user exits the activity. The length of the toast is short. Length of the toast cannot be changed as the text is long. This is what i have tried as of now: Toast toast; toast=Toast.makeText(getApplicationContext(),"text",Toast.LENGTH_SHORT); if(toast.getView().isShown()==false){ toast.show(); } This did not work. I tried : if(toast.getView().isShown()==true){

accessibility service is not started

橙三吉。 提交于 2019-11-26 19:16:26
问题 I want to log all toasts events in android ics (4.0.3), but I was unable to log any system event. Service is just not started! According to this question: onAccessibilityEvent(AccessibilityEvent event) not intercepting notification MyAccessibilityService.java package com.test.toasts2; import android.accessibilityservice.AccessibilityService; import android.accessibilityservice.AccessibilityServiceInfo; import android.app.Notification; import android.os.Parcelable; import android.util.Log;