安卓疑难杂症解决指南
1.
\u3000
用于TextView中文字的空格
2.
android怎样将textview置于imageview之上
使用FrameLayout布局
FrameLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>
<ImageView
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="33dp"
android:background= "@mipmap/ic_line1"
android:layout_weight="0.03" />
<TextView
android:textColor="@color/black"
android:layout_marginTop="58dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/langduzhe"
android:layout_weight="0.03" />
</FrameLayout>容
3.
android TextView改变部分字体颜色
textview = (TextView) findViewById(R.id.textview);
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(textview.getText().toString());
//ForegroundColorSpan–文字前景色,BackgroundColorSpan–文字背景色
ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);
ssbuilder.setSpan(yellowSpan, 11,15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textview.setText(ssbuilder);
4.
解决Android 5.0以上版本Button自带阴影效果的方法
style=”?android:attr/borderlessButtonStyle”
5.
设置背景图片透明
View v=findViewById(R.id.image4);
v.getBackground().mutate().setAlpha(190);
6.
设置收藏按钮类似的点击变换图片再点击恢复
final ImageButton button = (ImageButton) view.findViewById(R.id.bt_love);
final int[] flag = {0};
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(flag[0] ==0){
button.setBackgroundResource(R.mipmap.ic_love_normal);
flag[0] = 1;
}else{
button.setBackgroundResource(R.mipmap.ic_love_select);
flag[0] = 0;
}
}
});
2017.5.11
7.取消 EditText 自动聚焦弹出输入法界面
在EditText的父控件中加上这两行代码即可:
android:focusable="true"
android:focusableInTouchMode="true"
2017.6.6
8.取消android studio默认大写
在Values下的styles.xml中加入
<item name="android:textAllCaps">false</item>
即可。
9.给按钮增加水波纹
android:background="?attr/selectableItemBackground"