Editext、TextView、ImageView、Button、Toast设置

Editext相关:

android:inputType="textMultiLine"// 允许多行显示
android:minLines="6" //最小显示6行
android:gravity="left|top"//输入时光标、文字在左上角
android:gravity="center" // 字体居中
android:gravity="end"    // 字体居右
android:background="@null" //不显示下面的横线
android:cursorVisible="true"   // 显示光标
android:textCursorDrawable="@null"   // 设置为和文字字体一样的颜色
android:textCursorDrawable="@color/colorPrimary"   //设置其他颜色

光标不显示还可能是光标颜色和背景颜色混在一起了,比如光标为白色 而背景又设置为白色了

也可以自定义光标颜色
zidingyi.xml

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#0060d8" />
    <size android:width="1dp"/>

Editext 或者TextView的 cursor pointer(即选中文字的底部的三个小图标) 样式:
系统自带的pointer样式的颜色 为colorAccent的颜色!
而样式根据不同版本的不同有不同的默认样式 如7.0的类似水滴状
若没有默认的
则在Theme中加: style.xml 的Theme标签中加:

 <item name="android:textViewStyle">@android:style/Widget.TextView</item>

自定义选择文字的光标点的样式:

android:textSelectHandle="@mipmap/cursor_pointer_0060d8_32"
android:textSelectHandleLeft="@mipmap/cursor_pointer_0060d8_32"
android:textSelectHandleRight="@mipmap/cursor_pointer_0060d8_32"

设置文字选择的颜色变化:

android:textColorHighlight="@color/tianLanSe"

TextView的设置也一样的


android:textCursorDrawable="@drawable/zidingyi" 

改hint的 颜色

 android:textColorHint="@color/colorAccent"

设置输入为密码模式 (即隐藏显示)

android:inputType="textPassword"

可接收键盘输入

android:focusable="true"

点击另一个控件或者空白区域,当前Editext的输入键盘未隐藏
将软键盘隐藏掉

    /**
     * 点击空白区域隐藏键盘
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (NewAdd0Activity.this.getCurrentFocus() != null) {
                if (NewAdd0Activity.this.getCurrentFocus().getWindowToken() != null) {
                    if (imm != null) {
                        imm.hideSoftInputFromWindow(NewAdd0Activity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                    }
                }
            }
        }
        return super.onTouchEvent(event);
    }

    /**隐藏键盘 */
    protected void hideInputKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }

    /**弹起键盘 */
    protected void showInputKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.showSoftInput(v, 0);
        }
    }

让输入法弹出不会使控件或者布局顶上去

在Manifest.xml的相应的Activity中

 <activity android:name=".CRM.ChooseCustomerActivity"
            android:windowSoftInputMode="adjustPan|stateHidden"
            >
        </activity>

控制Editext显示的大小 但是内容不限制 超出显示变成可以滚动

设置固定的高度 并且设置

android:inputType="textMultiLine"

即可自动滚动 要看垂直滚动条则加上

android:scrollbars="vertical"

设置了边框,光标被边框遮挡

设置paddingLeft 就可以让文字 光标 靠右 不被边框遮挡

android:textCursorDrawable="@drawable/blue_cursor_2dp"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:width="2dp" />
    <solid android:color="@color/colorPrimary"  />
</shape>

使光标移动到指定的位置

editText.setSelection(2)

但是 前提是 要有text内容


TextView相关

设置可点击复制

android:textIsSelectable="true"

可以点击跳转打电话

android:autoLink="phone"

java代码中设置

biniuPhone.setAutoLinkMask(Linkify.ALL);
android:linksClickable="true"
android:autoLink="all"
 <!--允许拨打电话-->
    <uses-permission android:name="android.permission.CALL_PHONE" />

问题:要不看不到 打的了电话 要不 看的到号码 打不了电话
放在setText前 还是看不到 但是可以点击跳转打电话
setText后 看得到 但是点击不了


ImageView相关

java中设置 ImageView的背景

 imageView0.setImageResource(R.mipmap.other_arrows_up);

图片宽度不够
可以在xml的imageView中

android:scaleType="centerCrop"

图片填充imageView 但是可能不完全显示

或者

android:scaleType="fitXY"

填充ImageView 图片可能会被拉长


监听点击事件
跳转Activity
看那个 工具类

activity设置通知栏黑色(若通知栏是透明的或者自适应颜色就不必)

设置NotitleBar模式的先
android:theme=”@style/Theme.AppCompat.Light.NoActionBar”
然后通过
StatusBarUtils
设置通知栏颜色
android:screenOrientation=”portrait” 竖屏
landscape 横屏

总结


Button

1 要按钮背景透明

 android:background ="@android:color/transparent"

2 .java中设置背景资源

setBackgroundResource(R.drawable.gray_circle_corner)

Toast

Toast.makeText(WaiQinActivity.this, getString(R.string.waiqin),Toast.LENGTH_SHORT)
.setGravity(Gravity.BOTTOM, 0, 0).show();

不能使用链式写法

Toast toast = Toast.makeText(this, getString(R.string.pleaseOpenGps), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();

猜你喜欢

转载自blog.csdn.net/weixin_37577039/article/details/79777510