Click on the text to achieve text conversion, only use the array, as well as animation effects, event monitoring.
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <TextswitcherAndroid:id= "@+id/textswitcher1"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"android:inanimation= "@android: Anim/slide_in_left"android:outanimation= "@android: Anim/slide_out_right"Android:onclick= "Next"/></LinearLayout>
PackageCom.example.textswitcher;Importandroid.app.Activity;ImportAndroid.graphics.Color;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.TextSwitcher;ImportAndroid.widget.TextView;Importandroid.widget.ViewSwitcher.ViewFactory; Public classMainactivityextendsActivity {textswitcher textswitcher; String[] STRs=Newstring[]{"Advanced mathematics", "Linear algebra", "Discrete Mathematics", "Android Handout" }; intCurstr; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Textswitcher=(Textswitcher) Findviewbyid (r.id.textswitcher1); Textswitcher.setfactory (Newviewfactory () {@Override PublicView Makeview () {TextView TV=NewTextView (mainactivity. This); Tv.settextsize (40); Tv.settextcolor (Color.magenta); returnTV; } }); Next (NULL); } Public voidNext (View v) {textswitcher.settext (Strs[curstr++%Strs.length]); } }
Android 26th Lesson--textswitcher