android常见问题3

1.软键盘处理方式

//关闭软键盘
private void hintSoftInput() {
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    if(imm != null && imm.isActive()&&getCurrentFocus()!=null){
        if (getCurrentFocus().getWindowToken()!=null) {
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}

//如果显示则隐藏,如果隐藏则显示
private void changeSoftInput() {
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    // 得到InputMethodManager的实例
    if (imm.isActive()) {
        // 如果开启
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
                InputMethodManager.HIDE_NOT_ALWAYS);

    }
}

2.包含虚拟键盘的高度处理

//判断是否有虚拟键盘
@SuppressLint("NewApi")
public static boolean checkDeviceHasNavigationBar(Context activity) {

    //通过判断设备是否有返回键、菜单键(不是虚拟键,是手机屏幕外的按键)来确定是否有navigation bar
    boolean hasMenuKey = ViewConfiguration.get(activity)
            .hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap
            .deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey) {
        // 做任何你需要做的,这个设备有一个导航栏
        return true;
    }
    return false;
}

//获取虚拟键盘高度
public static int getNavigationBarHeight(Context activity) {
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height",
            "dimen", "android");
    //获取NavigationBar的高度
    int height = resources.getDimensionPixelSize(resourceId);
    return height;
}

3.让图片显示在状态栏上

分别创建values、values-v19、values-v21三个目录,分别在三个目录下创建styles.xml文件,依次添加下面代码

-value-

<style name="TranslucentSystemBar" parent="Theme.AppCompat.Light.NoActionBar"/>

-values-v19-

 <style name="TranslucentSystemBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

-values-v21

 <style name="TranslucentSystemBar" parent="Theme.AppCompat.Light.NoActionBar" >
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <!--Android 5.x 开始需要把状态栏颜色设为透明,否则会呈现系统默认的灰色-->
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

最后在布局页面的根布局添加

android:fitsSystemWindows="false"

在Manifest中添加主题样式

android:theme="@style/TranslucentSystemBar"

4.recycleView分组布局可参照

https://blog.csdn.net/xfhy_/article/details/78328983

5.A->B->C->D   界面依次跳转后,要从D按返回跳转B

在Intent中加入

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);//隔级跳转

可跳转中将C出栈。

6.列表水波纹样式 系统自带样式

android:background="?android:attr/selectableItemBackground"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值