1. 程式人生 > >簡單文字跑馬燈/popupwindow

簡單文字跑馬燈/popupwindow

自定義一個View繼承TextView

public class MarqueeTextView extends TextView{
    public MarqueeTextView(Context context) {
        super(context);
    }
 
    public MarqueeTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
 
    public MarqueeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
 
    }
 
    @Override
    public boolean isFocused() {
        return true;
    }
}

在activity_main.xml中呼叫

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f0f"
    android:gravity="center"
    android:orientation="vertical">
 
    <fanruiqi.bwie.com.week220181205.util.MarqueeTextView
        android:id="@+id/tv_runHorseLamp1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="這是一段很長的威武霸氣的滾動的實現跑馬燈效果的一段逼格很高的很有含義和涵養的文字"
        />
</LinearLayout>

popupwindow

public void onclick(view v){
  String s[] = {"找回密碼","簡訊驗證碼登入","郵箱/使用者名稱登陸"};
  AlertDialog Builder builder= new AlertDialog Builder(MainActivity this);
  builder.setItems(s, new DialogInterface OnclickListenero{
  @Verride
  public void onclick(DialogInterface dialog, int which)
       switch(which){
           case 0:
               break;
           case 1:
               break;
           case 2:
               break;
         } 
      }
  });
  builder. show();