1, customizing the TextView to get focus
Focustextview.java
1 PackageCom.itheima.mobilesafe74.view;2 3 ImportAndroid.content.Context;4 ImportAndroid.util.AttributeSet;5 ImportAndroid.widget.TextView;6 7 /**8 * @authorGCP9 * Custom TextView to get the focusTen */ One Public classFocustextviewextendsTextView { A //use to create controls through Java code - PublicFocustextview (Context context) { - Super(context); the } - - //called by the system (with attribute + Contextual environment construction method) - PublicFocustextview (Context context, AttributeSet attrs) { + Super(context, attrs); - } + A //constructed by system call (with attribute + Contextual environment construction method + layout file defined style file) at PublicFocustextview (context context, AttributeSet attrs,intDefstyle) { - Super(context, attrs, defstyle); - } - - //override the method that gets the focus, called by the system, to get the focus by default when called - @Override in Public BooleanisFocused () { - return true; to } +}Focustextview
Activity_home.xml Custom Get focus This part of the code:
<com.itheima.mobilesafe74.view.focustextview android:layout_width= "match_parent" android:layout_ height= "Wrap_content" android:ellipsize= "marquee" android:marqueerepeatlimit= "Marquee_forever " android:padding= "5DP" android:singleline= "true" android:text= "fall quietly in autumn, leave a little secret, ah ah ah ah ah ah, oh ah ah ah ah ah ah ah ah ah ah! android:textcolor= "#000" > </com.itheima.mobilesafe74.view.FocusTextView>
Android Phone defender--home Page