AndroidBug5497Workaround (用我这个就够了)

本文介绍了一个针对AndroidWebView中软键盘遮挡输入框的解决方案,通过AndroidBug5497Workaround类,监听输入框的全局布局变化,动态调整布局以适应键盘显示/隐藏,提供简单易用的在ActivityonCreate中的集成示例。

 webview加载网页『软键盘挡住了输入框』,是因为安卓本身的bug,即AndroidBug5497Workaround ;

关于5497的问题,网上也是杂七杂八给了各种方案,试了一天,用我这个方案完美解决问题,所以被5497问题困扰的话,直接copy吧

/**
 * 解决WebView中输入时弹出软键盘,挡住输入框的问题
 */

public class AndroidBug5497Workaround {
    // For more information, see https://issuetracker.google.com/issues/36911528
    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

    public static void assistActivity (Activity activity) {
        new AndroidBug5497Workaround(activity);
    }

    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                possiblyResizeChildOfContent();
            }
        });
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
    }

    private int frameLayoutHeight = 0;

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutHeight = frameLayoutParams.height;// !!!修改前保存原有高度
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            } else {
                // keyboard probably just became hidden
                if(0 != frameLayoutHeight) {
                    frameLayoutParams.height = frameLayoutHeight;// !!!收起键盘恢复原有高度
                }
            }
            mChildOfContent.requestLayout();
            usableHeightPrevious = usableHeightNow;
        }
    }

    private int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    }
}

使用方法也很简单 就是在 webactivity 的 onCreate的方法里直接调用

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_iweb);
        AndroidBug5497Workaround.assistActivity(this);
    }

### Azure Linked Service 2.0 中 Workaround 参数的配置位置 在 Azure Data Factory 的 Linked Service 2.0 配置中,`workaround` 参数通常作为一个扩展字段被定义在 `typeProperties` 或 `annotations` 节点下[^1]。尽管该参数并非官方标准字段,但它可以用于解决特定场景下的兼容性问题或提供额外的自定义配置选项。 #### 配置位置及示例 1. **在 `typeProperties` 下定义** 如果 `workaround` 参数与连接类型的核心功能直接相关,则可以将其放置在 `typeProperties` 节点下。以下是一个 JSON 示例: ```json { "name": "MyLinkedService", "properties": { "type": "CustomType", "typeProperties": { "url": "https://example.com/api", "authenticationType": "OAuth2", "clientId": "1234567890abcdef", "clientSecret": "your-secret-key", "workaround": { "customHeader": "X-Custom-Auth-Token", "timeoutInSeconds": 120 } } } } ``` 在此示例中,`workaround` 参数位于 `typeProperties` 下,包含两个子字段:`customHeader` 和 `timeoutInSeconds`[^1]。 2. **在 `annotations` 下定义** 如果 `workaround` 参数仅作为元数据或注释存在,而不直接影响连接行为,则可以将其放置在 `annotations` 节点下。以下是一个示例: ```json { "name": "MyLinkedService", "properties": { "type": "CustomType", "typeProperties": { "url": "https://example.com/api", "authenticationType": "Basic", "username": "user", "password": "pass" }, "annotations": [ { "name": "workaround", "value": { "customAuthLogic": "BearerToken", "retryCount": 3 } } ] } } ``` 在此示例中,`workaround` 参数通过 `annotations` 节点定义,适用于需要记录但不直接影响核心逻辑的场景[^2]。 #### 注意事项 - **非标准字段**:由于 `workaround` 不是 Azure 官方文档中的标准字段,因此其使用可能因具体版本或服务而异。建议在生产环境中谨慎使用,并确保对其进行充分测试。 - **安全性**:如果 `workaround` 参数涉及敏感信息(如认证令牌或密钥),务必遵循 Azure 数据工厂的安全最佳实践,确保这些信息不会被意外泄露。 - **版本兼容性**:Azure Data Factory 的不同版本可能对自定义字段的支持程度有所不同。在升级到新版本时,需验证 `workaround` 参数是否仍然有效[^3]。 --- ###
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值