安卓菜鸡 2017-10-20 05:34 采纳率: 0%
浏览 929
已采纳

安卓在适配器里面设置屏幕透明度

怎么才能在适配器里面得到getWindow方法啊传个context不行 又不能传getActivity
怎么才能拿到给getWindow..getAttributes()
public void backgroundAlpha(float bgAlpha)
{
WindowManager.LayoutParams lp =getWindow().getAttributes();
lp.alpha = bgAlpha; //0.0-1.0
getWindow().setAttributes(lp);
}

  • 写回答

1条回答 默认 最新

  • Grindstone_Fos 2017-10-20 07:19
    关注

    把Activity对象作为参数传过去啊。。在adapter的构造方法里面加上Activity参数啊
    getWindow()是Activity类的方法。

    /**
     * Retrieve the current {@link android.view.Window} for the activity.
     * This can be used to directly access parts of the Window API that
     * are not available through Activity/Screen.
     *
     * @return Window The current window, or null if the activity is not
     *         visual.
     */
    public Window getWindow() {
        return mWindow;
    }
    

    例子:
    Class TestActivity:
    ...
    TestAdapter adapter = new TestAdapter(this);
    ...

    Class TestAdapter:
    ...
    Activity mActivity;
    TestAdapter(Activity activity){
    mActivity = activity;
    }
    ...
    public void backgroundAlpha(float bgAlpha)
    {
    WindowManager.LayoutParams lp =mActivity.getWindow().getAttributes();
    lp.alpha = bgAlpha; //0.0-1.0
    getWindow().setAttributes(lp);
    }
    ...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据