|
- --编辑框封装8 {. _6 R6 h$ ^( I* X7 ^, d X
- --Pretend
5 X+ L1 n. z! R) E% w5 X8 D - require "import"
( U$ s* y- h) o2 L - import "android.app.*"( C& H- K+ g: F+ W+ b
- import "android.os.*"
6 S( s7 q5 l7 t! o - import "android.widget.*"
$ `+ u* ]3 _3 Y, o, ]" g$ @ - import "android.view.*") ], k! G# T0 v. n7 E
- . ~; d* t a# I8 h+ S' ]& V
- function PretendEditText(t)--编辑框封装( }0 C" i7 q" t1 W+ q7 j
- local lay=loadlayout{FrameLayout," p: `. y/ p5 V( c8 R0 @6 C D7 L
- {
+ k0 Q2 X* q' z8 L* h- M. p, ?: s, H! K - RelativeLayout;3 N4 c3 Y# s0 F: Q6 H
- layout_width="fill";
7 I+ L. b2 z( c( V; g; H: Q - focusableInTouchMode=true;8 l2 T! z U, d1 c2 ?1 E- k
- focusable=true;
' r1 B! [" F, n7 l$ Y8 | - layout_height="fill";/ f/ O/ H7 r: x& d" {
- {
/ ]1 {, K3 U( v5 V/ @ - EditText;
. m; @2 H, B- d4 H3 ] - layout_height="wrap";
' A1 q3 j; o1 l. v4 {& x# r - layout_marginTop="56";1 N5 H+ ^* X: T8 L5 _
- layout_centerHorizontal="true";
$ Y+ [# i4 ]/ }# F- Y2 r& B - textColor=t.字体颜色 or "#000000";
/ Z6 p& E& _* |4 z9 n. M$ u/ h - textSize="14dp";2 Y' ?2 h3 q, h, M( {8 U/ T
- background="0";' t9 J/ j+ \4 ~
- layout_marginLeft="16dp";4 G9 N" U- q0 w2 |5 S9 m
- layout_width="fill";
$ d* u4 |5 i+ X8 l - layout_marginRight="16dp";7 D; B4 n: g, \1 `( n) \
- id=t.id;$ }# x1 V3 v: b9 S; x1 r* z1 P0 q
- password=t.password;4 Z0 g/ A( Q6 {; N* [2 }8 R9 F
- singleLine="true";8 b1 H. T+ {5 S
- };+ Z# |, W" t# @: X* y
5 F( t; e9 I+ _# U% V; v
a4 A; z7 I$ L- s3 d, |% M- {
% {, h% q* V4 _+ k3 F; l - TextView;
0 |6 Q$ H% i# Q3 g$ y - layout_height="2dp";
1 ~& L' @! k5 n, D - layout_alignBottom=t.id;# P- k5 G" K* g% v- z
- layout_centerHorizontal="true";3 B% x5 ^2 W4 Q" |
- background=t.线的颜色1 or "#009688"; Z( M$ j, M! B% Y
- layout_marginLeft="16dp";
) ]) I) C$ \/ F" K - layout_width="fill";
7 j9 q, W2 t6 U) o1 S, |6 Z5 o - layout_marginRight="16dp";
4 l& |( ?' z0 L0 u' B - alpha="1";
) H- K' ^2 N) f; R3 U - id=t.id2;6 u/ M# J6 ]! }% \; q4 F0 j
- }; l2 e$ `' [& y; U- L, t. ]9 x
' d5 A0 w# ^) W& @- {! c2 g8 z, x. j. G9 t) S
- TextView;
8 P9 C8 L# t- N6 C* k8 ]2 g - layout_height="1dp";
* e3 z" q; n: Z - layout_alignBottom=t.id;" I" `4 r0 f: t5 ]5 ^
- layout_centerHorizontal="true";: a) C, T9 {8 w7 d7 O8 y, _& W
- background=t.线的颜色2 or "#000000";
7 F" e. m9 ?' P' r; O% n - layout_marginLeft="16dp";
% S2 Q' E& ^6 `* w# v1 {' g - layout_width="fill";. y, _9 m( K& d5 [. k4 a1 t1 k
- layout_marginRight="16dp";3 H) n. Z6 [% |% K- c" r1 g
- alpha="0.2";
7 E, j8 A W' g0 h+ t# P# R; S - id=t.id4;
. Y* @. b+ T* D' |; G5 B; B R - };
" l# | A: p6 A4 O
! k: ^2 |' F; u, q! S5 T( O9 d- {
; P- G8 p5 \* H+ k" f - TextView;
! T9 G3 r- |3 |& {7 J. X - id=t.id3;
) Y; {/ Z; [& N - layout_marginLeft="24dp";
* r) m5 {. ?$ [1 C7 z - text=t.hint or "Pretend封装";" [0 [5 U: x3 \: J- K
- layout_alignBaseline=t.id;
' Z3 r6 K8 ~& X - textSize="14dp";
" s- e9 J; m# _; J+ [' l0 e - };
2 J0 l0 Z- r" c# }) B - };}
# _- y% h B4 K$ [4 O4 N8 t - 7 @0 |6 ?9 L) z2 O- L2 y
- 值=true; ?7 L0 a& D4 m; W6 j
6 v0 q$ O, v& `% }* z/ W& m S- lay.getChildAt(0).getChildAt(0).setOnFocusChangeListener{: U& ?. N, Q2 J3 Y
- onFocusChange=function( v, hasFocus). U, Z5 {) z9 V. a& K! B) j, z
- if hasFocus then( n2 E! d/ w9 G$ x0 D
- 1 H! Y4 X: K3 g& L d
- import "android.view.animation.ScaleAnimation" G% k+ Q* ~/ y" [
- lay.getChildAt(0).getChildAt(1).startAnimation(ScaleAnimation(0.0,1.0,1.0,1.0,1,0.5,1,0.5).setDuration(200))
; q: |0 |3 {, P+ S- H3 J8 f - lay.getChildAt(0).getChildAt(1).setVisibility(View.VISIBLE)
/ _! N# l0 D6 ]5 X& \" [5 W - if lay.getChildAt(0).getChildAt(0).Text=="" then
/ u% h+ T1 h- W+ | - import "android.view.animation.TranslateAnimation"
7 g4 {% R6 w% {9 m) ] - lay.getChildAt(0).getChildAt(3).startAnimation(TranslateAnimation(0,0,0,-56).setDuration(100).setFillAfter(true)); G$ |2 f0 r. V4 s* |
- end2 X' N9 D* l3 _+ Y! m7 _
# g. X6 ~. x+ [4 z- _- else
/ }' b: c8 T% M9 @- A6 ? - 1 l' B' z# w6 Z9 {! R4 H7 v$ Q
- lay.getChildAt(0).getChildAt(1).startAnimation(ScaleAnimation(1.0,0.0,1.0,1.0,1,0.5,1,0.5).setDuration(200))0 S: O/ P8 w- p
- lay.getChildAt(0).getChildAt(1).setVisibility(View.INVISIBLE)
2 ?3 A5 b: V: P% x0 U - if #lay.getChildAt(0).getChildAt(0).Text==0 then
6 ?' x( Q* N6 p - lay.getChildAt(0).getChildAt(3).startAnimation(TranslateAnimation(0,0,-56,0).setDuration(100).setFillAfter(true))/ C3 C. }. `; ~/ c1 j( @
- else
$ k5 T2 z9 F" ^- H& F - lay.getChildAt(0).getChildAt(3).setTextColor(t.hint颜色1 or 0xff009688)
9 ^5 z- {9 b% h! g- \. S; y - end4 q3 Y+ F4 X" D" G
- 8 v: o& ?, C: U2 j9 j) C) R/ x
- end7 i$ u! p5 z+ P0 X' O+ M$ H7 B$ u
- end}
/ i% |4 z) A1 K" l - lay.getChildAt(0).getChildAt(0).addTextChangedListener{3 s/ M) c7 ?0 N- |+ E
- onTextChanged=function(s)" B5 W2 o) k8 K) z4 p: A
- 内容=tostring(lay.getChildAt(0).getChildAt(0).Text)
; B- C1 I+ p6 P) q/ b3 q3 l# S - if #内容==0 then
9 p& ~+ d# P- r1 } - lay.getChildAt(0).getChildAt(3).setTextColor(t.hint颜色2 or 0xff8b8b8b)+ q# N4 X, i( n1 D3 q
- else3 u6 {1 @+ B4 _8 M s
- lay.getChildAt(0).getChildAt(3).setTextColor(t.hint颜色1 or 0xff009688)
- t' b/ H; i; }8 o& b - end! U& H" w1 A9 S, }- }! P
- end
9 Q6 x ^2 ]) M- J& ^) U - }
$ F2 Q! h# j) M- v! N) x - + B! {# s( h, ]$ Y* K
. W. e) T$ J2 `- lay.getChildAt(0).getChildAt(1).setVisibility(View.INVISIBLE)
% ^% h6 N6 V9 c& Y/ j# z - 1 X: d" C; d3 }1 e- t+ p
- function 取消焦点(app)# B9 s6 E4 W8 q" N' H. _$ o5 U1 `3 {
- app.setFocusable(false);/ P# b9 h! `2 O" z. H5 C5 v
- app.setFocusableInTouchMode(true);4 O% a" G' v5 Q" H- U
- end% k4 n; L z2 E+ i. A
, Q. z- H; b7 s0 r6 [- return function() return lay end- O- m& H; \4 \3 M# Y$ {
- end
6 W/ s* n2 P" q% G% @2 A' k2 W
# \! U2 ^3 I$ ~! E* D6 ]- --主布局,导入封装模块必须在布局前面0 p4 H0 ?% I9 Y
- layout={ e; T+ {8 O/ z) p8 F8 b$ e
- LinearLayout;* n5 F( l7 G0 I+ \& c k/ K
- gravity="center";
: ]8 H- A7 L* f! |% r$ X - orientation="vertical";
0 r# h, |" E) n7 a0 C; v - {% z, y% [6 L+ c0 Q- ^) T
- PretendEditText
* d1 _9 v7 u# X# X - {
2 A, e, _8 i d* Y s1 v6 @ - id="app";! J% h% \ v3 p" |9 g+ h+ C9 s
- hint="账号";
; Y# A2 d# Y6 F% w - hint颜色1=0xFFE91E63;
! u' S0 R, r- v; ?+ y7 y) N; N - hint颜色2=0xff8b8b8b;
i* m: a5 {' N; R: ~ - 字体颜色="#000000";$ P6 @$ a7 B+ F5 z7 R s# n
- 线的颜色1="#FFE91E63";1 ?# b9 M7 C: H0 k: h4 e, F
- 线的颜色2="#ff8b8b8b";
9 w( f' h& z# G6 @ k2 N - };
8 E0 n+ J( B9 }- z - };
& R, e! U7 D5 b5 T) E& J. V( r - {" e4 m5 _: I1 y$ X2 x/ f# f) V
- PretendEditText( Y0 v5 @# w4 N0 g: R' i
- {: `$ Q: C+ J) o/ l& U4 w. K
- id="ap47p";; `- R+ p+ X* [1 i
* v& }# }; s' p& { v" F- hint="密码";
{! k- }+ b* V - password=true;1 O$ i: e4 a+ c
- 字体颜色="#000000";
" |3 j) I$ Y* D% N! x! T% p, {. Z - hint颜色1=0xFFE91E63;" p' H3 C- P! e' U0 U2 C0 y
- hint颜色2=0xff8b8b8b;+ z8 L" L9 ^5 W5 Q1 @
- 线的颜色1="#FFE91E63";: D. S3 E9 Q% n& S! E
- 线的颜色2="#ff8b8b8b"; {( E. q; ?2 ^6 u. u, X8 r2 |
- };( B4 m# a7 Z8 J6 X9 g! p V N
- };2 u7 s: m8 L: D4 }0 P
- {' L/ f2 M' p( j: q6 H7 E' ?& P
- Button;
6 f4 e/ H( D1 W1 T' K6 q) @8 c - id="apo";, r, }" ~9 g" M/ o1 q3 o/ h
- layout_marginLeft="10dp";9 m2 f* G' ~5 L- n3 d
- layout_width="fill";
' x4 O- m x7 d W7 R5 L - text="确定";
( |3 \/ F9 X( J/ | - layout_marginRight="10dp";
1 x2 D0 s+ F& Z& T& c" i& O - layout_marginTop="56";
! k* e$ Y. h* b; [" k; B- V! d - };
, F, O& e- @" G1 D7 j; k - };0 x: t- v& u; T! b, U
- 6 b8 ?' R- G/ ~1 @2 X% \6 v. d
- activity.setContentView(loadlayout((layout)))
! H t. }# Z1 j, F" W( i' d& | ?( q
. n( S+ m! g% C- function apo.onClick()% b) X# y. w; m1 F; h' U
- 取消焦点(app)4 ?2 d) T2 O* J6 }
- 取消焦点(ap47p)5 x# S+ J; |" z- _( N
- end+ z$ L. Q C& P
: I3 y g8 H! _. I' D/ @: C- V
复制代码 |
|