Android studio

控件 – TextView

正规开发是写到res/values中,不是写在TextView中

android:id=”@+id/tv_one” android:text=”@string/tv_one” android:textColor=”#FF000000″ android:layout_width=”match_parent” android:textStyle=”italic” android:layout_height=”200dp” android:textSize=”30sp” android:background=”#00000000″ android:gravity=”left”

layout_out

组件的高度

  • fill_parent 直接说出数字,如20dp
  • match_parent 指的是textview的宽度取的是LinearLayout的宽度
  • wrap_content 根据TextView里面的内容自动增倍宽度,但不超过容器
id

为TextView设置一个组件id

android:id=”@+id/tv_one” 在activity_main输入

TextView tv_one = findViewById(R.id.tv_one); tv_one.setText(“Led”); 在MainActivity的onCreate()输入

text

设置显示的文本内容

但是在id中重写方法会重新赋值text,输出为led

textClolor

设置字体颜色

android:textColor=”#00000000″

八位

前两位为透明度,00指的是透明,FF不透明

3-4位:红 #FFFF0000

5-6:绿 #FF00FF00

7-8:蓝#FF0000FF

textStyle

设置字体风格

  • normal默认
  • bold 加粗
  • italic斜体
textSize

字体大小,单位一般是用sp

background

控件的背景颜色,可以理解为填充整个控件的颜色,可以是图片

颜色和字体颜色一样

gravity

设置控件中内容的对齐方向,TextView中是文字,ImageView中是图片

center_horizontal 水平居中

center_vertical 垂直方向居中

带阴影的TextView

android:shadowRadius=”3.0″ android:shadowColor=”@color/lv” android:shadowDx=”10.0″ android:shadowDy=”10.0″

实现跑马灯效果

被弃用但是还能用

ellipsize省略号的位置

android:singleLine=”true” android:ellipsize=”marquee” android:marqueeRepeatLimit=”marquee_forever” android:focusable=”true” android:focusableInTouchMode=”true” android:clickable=”true”

控件 – button

随着按钮的状态改变背景色或背景的状态,主要根据StateListDrawable设置