当前位置: 首页 > article >正文

Android Toast在指定的Display里面显示

Android Toast在指定的Display里面显示

TextView toastTextView = null;
Toast inputModeToast = null;
private LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, Gravity.CENTER);


private void createInputModeToast(){
    DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
    Display targetDisplay = displayManager.getDisplay(mDisplayID);
    Context targetContext = createDisplayContext(targetDisplay);

    toastTextView = new TextView(targetContext);
    toastTextView.setLayoutParams(layoutParams);
    toastTextView.setWidth(420);
    toastTextView.setHeight(68);
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(0xffffffff);
    drawable.setCornerRadius(36);
    toastTextView.setBackground(drawable);
    toastTextView.setGravity(android.view.Gravity.CENTER);
    String message = mContext.getString(R.string.input_mode_message) + " " + mDBInputMode;
    toastTextView.setText(message);
    inputModeToast = Toast.makeText(targetContext, message, Toast.LENGTH_LONG);
    inputModeToast.setView(toastTextView);
    inputModeToast.setGravity(Gravity.CENTER, 0, 350);
    Log.d(TAG, "createInputModeToast, target display id=" + targetDisplay.getDisplayId());
}

runOnUiThread(()->createDBInputModeToast());

private void processDBInputModeChange(int mode){
    mDBInputMode = mode;

    if(inputModeToast != null && toastTextView != null) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                String message = mContext.getString(R.string.input_mode_message) + " " + mDBInputMode;
                Log.d(TAG, "processInputModeChange message=" + message);
                toastTextView.setText(message);
                inputModeToast.show();
            }
        });
    }
}

TextView toastTextView = null; Toast inputModeToast = null; private LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, Gravity.CENTER); private void createInputModeToast(){ DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); Display targetDisplay = displayManager.getDisplay(mDisplayID); Context targetContext = createDisplayContext(targetDisplay); toastTextView = new TextView(targetContext); toastTextView.setLayoutParams(layoutParams); toastTextView.setWidth(420); toastTextView.setHeight(68); GradientDrawable drawable = new GradientDrawable(); drawable.setColor(0xffffffff); drawable.setCornerRadius(36); toastTextView.setBackground(drawable); toastTextView.setGravity(android.view.Gravity.CENTER); String message = mContext.getString(R.string.input_mode_message) + " " + mDBInputMode; toastTextView.setText(message); inputModeToast = Toast.makeText(targetContext, message, Toast.LENGTH_LONG); inputModeToast.setView(toastTextView); inputModeToast.setGravity(Gravity.CENTER, 0, 350); Log.d(TAG, "createInputModeToast, target display id=" + targetDisplay.getDisplayId()); } runOnUiThread(()->createDBInputModeToast()); private void processDBInputModeChange(int mode){ mDBInputMode = mode; if(inputModeToast != null && toastTextView != null) { runOnUiThread(new Runnable() { @Override public void run() { String message = mContext.getString(R.string.input_mode_message) + " " + mDBInputMode; Log.d(TAG, "processInputModeChange message=" + message); toastTextView.setText(message); inputModeToast.show(); } }); } }


http://www.kler.cn/a/519732.html

相关文章:

  • [RoarCTF 2019]Easy Calc1
  • Vue入门(Vue基本语法、axios、组件、事件分发)
  • Flink把kafa数据写入Doris的N种方法及对比。
  • 【Postman接口测试】Postman的全局变量和环境变量设置
  • Windows Defender添加排除项无权限的解决方法
  • 案例研究丨浪潮云洲通过DataEase推进多维度数据可视化建设
  • TLF35584 基本介绍
  • JAVASE入门十脚-红黑树,比较器,泛型
  • 校园商铺管理系统设计与实现(代码+数据库+LW)
  • 计算机网络 (62)移动通信的展望
  • ChatGPT的本质是什么?
  • 一文详解Filter类源码和应用
  • Linux下php8安装phpredis扩展的方法
  • 【更正版】梯级水光互补系统最大化可消纳电量期望短期优化调度模型
  • Yocto项目 - 解读CROss PlatformS (CROPS)
  • 飞牛NAS安装过程中的docker源问题
  • 适配Android16
  • ClickHouse SQL 查询中别名导致报错的问题分析与解决方案
  • OS Copilot 功能评测:真的能提升效率吗?
  • 【2024年华为OD机试】(A卷,100分)- 网上商城优惠活动 (JavaScriptJava PythonC/C++)
  • 微信小程序获取位置服务
  • fpga系列 HDL:verilog 常见错误与注意事项 quartus13 bug 初始失效 reg *** = 1;
  • Solon Cloud Gateway 开发:Helloword
  • HTMLCSS :下雪了
  • Kafka运维宝典 (四)- Kafka 常用命令介绍
  • Vue.js 传递路由参数和查询参数