不定期更新,大多是一些老忘记的属性,奇怪的细节,奇技淫巧之类的
TextView限制行数及末尾已省略号显示
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是好长的文字我是好长的文字我是好长的文字我是好长的文字我是好长的文字我是好长的文字"
android:maxLines="3"
android:ellipsize="end"
android:maxLines=”3” 限制最大行数
android:ellipsize=”end” 末尾省略号
android:lines=”2” 显示两行,如果内容用一行就可以全部显示了,这时候TextView还是会占用两行的高度空间
tools属性,用来预览
例如text属性,在预览的时候会显示 tools:text 的内容,在正式运行的时候会显示 android:text 的内容。
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是实际的文字"
tools:text="我是预览文字"
tools属性在所有属性上都生效
使用时,系统会自动导入
xmlns:tools="http://schemas.android.com/tools"
命名空间
限制输入字符
设置EditText的android:digits 属性。
比如要限制只能输入数字和字母
android:digits="0123456789abcdefghijklmnopqrstuvwxyz"
不支持区间操作符~或-
TextView粗体
android:textStyle="bold"
ScrollView去掉拉到顶的动画跟滚动条
android:overScrollMode="never"
android:scrollbars="none"
RecycleView 嵌套惯性滑动问题
解决方法1:
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext){
@Override
public boolean canScrollVertically() {
return false;
}
};
recyclerView.setLayoutManager(layoutManager);
解决方法2:
使用NestedScrollView替换ScrollView
TextView文字,数字上下留白的问题
android:includeFontPadding="false"
即可消除
Dialog背景颜色深度
Dialog自带50%透明度的灰色遮罩层,若想修改遮罩层颜色深度,有两个思路
- 通过修改Style
<style name="DialogCustomStyle" parent="@android:style/Theme.Dialog">
<!-- 是否半透明 -->
<item name="android:windowIsTranslucent">true</item>
<!--是否无标题-->
<item name="android:windowNoTitle">true</item>
<!-- 背景透明 -->
<item name="android:windowBackground">@color/color_00000000</item>
<!-- 去除黑色边框的关键设置项,模糊 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 背景缓存颜色 -->
<item name="android:colorBackgroundCacheHint">@null</item>
<!-- 控制灰色遮罩颜色深度为70% -->
<item name="android:backgroundDimAmount">0.7</item>
</style>
通过 backgroundDimAmount来修改背景遮罩颜色深度,推荐这种方式,比较自然
- 通过取消遮罩层颜色,全屏dialog来做
<!-- 控制灰色遮罩颜色深度 -->
<item name="android:backgroundDimAmount">0</item>
getWindow().setBackgroundDrawable(new ColorDrawable(mContext.getResources().getColor(/*你的颜色*/)));
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
这种方式好处是更加灵活,但是遮罩层效果是跟随dialog出现效果,需要处理的东西比较多
CircleImageView + Glide 第一次展示只显示holder图片的问题
Glide.with(context.getApplicationContext())
.load(url)
.crossFade()
.placeholder(holder)
.error(holder)
.dontAnimate()
.into(iv);
重点 dontAnimate()
图片Uri
图片Uri跟文件的Uri格式不同,图片Uri为“content”开头的数据库资源文件,文件的Uri为“file”开头的文件,图片Uri不能直接转成文件,拿不到数据
可以参考博客
改变软键盘右下角的按键
android:imeOptions="actionDone"
可选项有
<!--actionDone:确定/完成-->
<!--actionGo:前进-->
<!--actionNext:下一项-->
<!--actionNone:默认-->
<!--actionPrevious:上一项-->
<!--actionSearch:搜索-->
<!--actionSend:发送-->
直接使用可能不会生效,需要配合
android:singleLine="true"
图片的scaleType
获取通知栏高度
int notificationBar = Resources.getSystem().getDimensionPixelSize(Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android"));
Fragment嵌套时,程序崩溃重启后内部Fragment白屏
内部Fragment应该使用 getChildFragmentManager ,而不是getFragmentManager,否则在重启之后会因为拿不到FragmentManager而白屏
Activity执行recreate()方法,dialog自动消失/不自动消失
public class MyDialog extends Dialog {
...
@Override
public void show() {
...
// 如果先执行show方法,再执行set params方法,当activity执行recreate重启的时候,dialog的显示状态不受影响
super.show();
getWindow().setAttributes(layoutParams);
}
}
...
public class MyDialog extends Dialog {
...
@Override
public void show() {
...
// 如果先执行set params方法,再执行show方法,当activity执行recreate重启的时候,dialog回自动销毁
getWindow().setAttributes(layoutParams);
super.show();
}
}
...
这个目前不知道是一个新特性,还是一个bug,谨慎使用