Android -ui控件
生活随笔
收集整理的這篇文章主要介紹了
Android -ui控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一:TextView控件
TextView --》 View
1.創建TextView的兩種方式:
1.1編寫TextView類TextView tv = new TextView(this); 1.2編寫xml文件<TextViewandroid:id="+id/text_view_id"android:layout_height="wrap_content"android:layout_width="wrap_content"android:text="@string/hello"/> 應用TextView控件:TextView tv = (TextView)findViewById(R.id.text_view_id);tv.setText(R.string.user_greeting);2.TextView屬性:
字體大小推薦使用sp作為單位;寬高屬性推薦使用dp作為單位 改變樣式:2.1textView.setText(Html.fromHtml("<font color=blue>歡迎!</font>"));2.2xml文件中添加樣式android:textSize="20sp"android:textColor="#00FF00" //改變全部字體顏色android:autoLink="all" //設置是否將文本為url鏈接/email/電話/map2.3String str = "歡迎收看系列課程";// class SpannableStringBuilder implements CharSequenceSpannableStringBuilder style = new SpannableStringBuilder(str);style.setSpan(new ForegroundColorSpan(Color.RED),0,6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);style.setSpan(new ForegroundColorSpan(Color.GREEN),6,21, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);style.setSpan(new ForegroundColorSpan(Color.BLUE),21,34, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//setText(CharSequence text)tv.setText(style);3.跑馬燈效果:
android:ellipsize="marquee" //當文字過長時,控件如何顯示 android:singleLine="true" //單行顯示文字 android:focusable="true" //控件是否能夠獲取焦點 android:focusableInTouchMode="true" //是否在觸摸模式下獲得焦點 android:marqueeRepeatLimit="marquee_forever" //滾動重復次數二:EditText控件
EditText --》 TextView --》 View --》 Object
1.去除EditText自動聚焦的方法:
<EditText android:layout-width="0dp"android:layout-height="0dp" />2.屬性設置
限制字符的輸入數量:android:maxLength="3" 多行文本框:android:singleLine="false" //true為單行文本框 限制EditText輸入信息:android:inputType="number" //限制文本輸入為數字 設置提示信息:android:hint="我是EditText" 在EditText中顯示圖片:android:drawableLeft="@drawable/title" 設置圓角:android:background="@drawable/shape"三:Button控件
Button --》 TextView
四:intent
1.撥打號碼
轉載于:https://www.cnblogs.com/itzlg/p/11104860.html
總結
以上是生活随笔為你收集整理的Android -ui控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一、Iframe
- 下一篇: Android 小项目之--Mini音乐