安卓学习日记DAY1:
TextView 组件属性:
属性 | 解析 |
---|
layout_width | 组件的宽度 |
layout_height | 组件的高度 |
id | 为TextView 设置一个组件id相当于变量名 |
text | 设置显示的文本内容 |
textColor | 设置字体颜色 |
textStyle | 设置字体风格,normal(无效果)、bold(加粗)、italic(倾斜) |
textSize | 字体大小,单位一般用sp |
background | 控件背景颜色,可以使用图片 |
gravity | 设置空间中内容的对齐方向 |
shadowColor | 设置阴影颜色,要与shadowRadius一起使用 |
shadowRadius | 设置阴影模糊度,建议3.0 |
shadowDX | 设置阴影水平方向偏移,既阴影位置横坐标 |
shadowDY | 设置阴影竖直方向偏移,既阴影位置纵坐标 |
singleLine | 内容单行显示 |
focusable | 是否可以获取焦点 |
focusableInTouchMode | 触摸模式下是否获取焦点 |
marqueeRepeatLimit | 重复动画次数 |
ellipsize | 省略文本 |
快捷键Ctrl+左键跳转到方法或者定义
text 、color、themes等内容应放在 目录res/valuses/.xml中**
<TextView
android:id="@+id/tv_one"
android:text="@string/tv_one"
android:textColor="@color/black"
android:textStyle="italic"
android:textSize="30sp"
android:background="@color/RED"
android:gravity="center_vertical"
android:shadowColor="@color/purple_700"
android:shadowRadius="3.0"
android:shadowDx="10.0"
android:shadowDy="10.0"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="200dp">
</TextView>
Button 组件属性:
属性 | 解析 |
---|
setOnClickListener | 点击事件 |
setOnLongClickListener | 长按事件 |
setOnTouchListener | 触摸事件 |
EditText组件属性:
属性 | 解析 |
---|
hint | 输入提示 |
textColorHint | 提示文本的颜色 |
inputType | 输入内容格式 |
drawable**** | 在文本框的某个位置添加图片 |
drawablePadding | 图片与输入内容之间的间距 |
padding | 内容与边框之间的间距 |
ImagView组件属性:
属性 | 解析 |
---|
src | 设置图片路径 |
scleType | 设置图片缩放类型 |
maxHeight | 最大高度 |
maxWeight | 最大宽度 |
adjustViewBounds | 调整View界限 |
ProgressBar(进度条)组件属性:
属性 | 解析 |
---|
max | 进度条最大值 |
style | 进度条样式("?android:attr/progressBarStyleHorizontal" 水平进度条) |
indeterminate | 设置为true是不显示精确进度,变为跑马灯形式 |
progress | 进度条已完成进度值(在acticvty中使用get和set的方法进行设置) |
Notification(通知)组件属性:
private NotificationManager manager;
private Notification notification;
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel("sab","测试通知",NotificationManager.IMPORTANCE_HIGH);
manager.createNotificationChannel(channel);
}
Intent intent = new Intent(this,NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0);
notification = new NotificationCompat.Builder(this,"sab")
.setContentTitle("集团通知")
.setContentText("防火演练")
.setSmallIcon(R.drawable.ic_baseline_add_business_24)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ceshi))
.setColor(Color.parseColor("#FF0000"))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build();
manager.notify(1,notification);
manager.cancel(1);
ToolBar(标题栏)组件属性:
style name="Theme.Zb" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"
main_xml中的ToolBar不是安卓自带的控件
<androidx.appcompat.widget.Toolbar
属性 | 解析 |
---|
navigationIcon | 左边的图标一般用于返回图标 |
title | 标题 |
titleMarginStart | 标题距离最左端的距离 |
logo | logo |
subtitle | 子标题 |
Toolbar toolbar = findViewById(R.id.tb);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
AlertDiaLog(标题栏)组件属性:
View Dialog =getLayoutInflater().inflate(R.layout.dialog,null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.mipmap.ic_launcher)
.setTitle("提示")
.setMessage("错误")
.setView(Dialog)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.e("sab","点击了确定");
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.e("sab","点击了取消");
}
})
.setNeutralButton("中间", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.e("sab","点击了中间");
}
})
.create()
.show();
PopupWindow(标题栏)组件属性:
View Pop=getLayoutInflater().inflate(R.layout.dialog,null);
Button PopCelBtn=Pop.findViewById(R.id.cancel);
PopupWindow popupWindow = new PopupWindow(Pop, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,true);
popupWindow.showAsDropDown(view);
PopCelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});