Project needs to be added to the PC version of the similar effect. For example, in employee Practice mode, several Chinese characters are constantly flashing in the middle of the screen: "Practice mode ".
Maybe this method is not good, but I did. It is assumed that the activity screen is complex.
The code is actually very simple and directly pasted.
Package com. example. sqlitepagetest; import android. app. activity; import android. graphics. color; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. view. gravity; import android. view. view; import android. widget. button; import android. widget. frameLayout; import android. widget. linearLayout. layoutParams; import android. widget. textView ;/****
* 11:52:59 PM ** @ auther dalvikCoder */public class Activity2 extends Activity {Button btn; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity2); btn = (Button) findViewById (R. id. btntrain); addAliveText ();} private TextView aliveText;/** text flashing thread **/private TextThread textThread = null; private void addAliveText () {aliveText = new TextView (this); aliveText. setText ("Exercise Mode"); aliveText. setTextColor (Color. RED); aliveText. setTextSize (50); aliveText. setBackgroundColor (Color. TRANSPARENT); aliveText. setGravity (Gravity. CENTER | Gravity. CENTER_VERTICAL); FrameLayout. layoutParams p = new FrameLayout. layoutParams (LayoutParams. MATCH_PARENT, LayoutParams. MATCH_PARENT, Gravity. CENTER | Gravity. CENTER_VERTICAL); this. addContentView (aliveText, p); if (textThread = null) {textThread = new TextThread (); textThread. start () ;}/ *** @ author Exercise Mode text flashing */public class TextThread extends Thread {@ Overridepublic void run () {do {try {Thread. sleep (1*1000); // The Message is flashed once every 1 s msg = new Message (); msg. what = 6; timeHandler. sendMessage (msg);} catch (InterruptedException e) {e. printStackTrace () ;}} while (true) ;}} private Handler timeHandler = new Handler () {@ Overridepublic void handleMessage (Message msg) {super. handleMessage (msg); switch (msg. what) {case 6: if (aliveText. getVisibility () = View. VISIBLE) {aliveText. setVisibility (View. INVISIBLE);} else if (aliveText. getVisibility () = View. INVISIBLE) {aliveText. setVisibility (View. VISIBLE) ;}break ;}}};}
When the activity is complex and the user clicks the screen to respond to the event, the flashing text does not affect event processing. Unless he is specially added with event listening.
Mobile phones use app treasure. The actual effect is faster and it feels better.
You can compare the differences between the two methods:
This. addContentView (aliveText, p );
SetContentView (R. layout. activity2 );