android - WindowManager.LayoutParams alpha issue -


in app, have service in create view display using windowmanger :

    mfilter = new view(this);     mfilter.setbackgroundcolor(getresources().getcolor(android.r.color.black));      mparams = new windowmanager.layoutparams(         layoutparams.type_system_overlay,         layoutparams.flag_layout_in_screen,         pixelformat.transparent); // pixelformat.translucent works      mwindowmanager.addview(mfilter, mparams);

i want able control opacity dynamically way :

    mparams.alpha = alpha; // alpha float chosen user , varying 0 1     mwindowmanager.updateview(mfilter, mparams);

the problem works on galaxy s3 under android 4.2.2, on galaxy ace under android 2.3.6, on emulator under android 2.3.3 but fails on galaxy y under android 2.3.3 : alpha cannot set value between 1 , 0, either transparent (0) or opaque (1). questions : have same issue ? occur phone ? there way solve or other wayto change opacity ? i've search web long time no 1 seems have experienced same thing... found workaround "half" works setting directly opacity of view :

    mfilter.getbackground().setalpha(alpha); // alpha int varying 0 255

the problem time on older version of android works on api 10 , lower, view's opacity doesn't update if call, mfilter.postinvalidate() or mwindowmanager.updateview(mfilter, mparams). have remove (mwindowmanager.removeview(mfilter)) , add again causes screen blink not acceptable...

it's kind of hack, due alpha changes in various android versions use alphaanimation set opacity of view, cause reliable way on older plattforms.

just give try:

float alpha = 0.5f; alphaanimation alphaanimation = new alphaanimation(alpha, alpha); alphaanimation.setstarttime(0); alphaanimation.setduration(0); alphaanimation.setfillafter(true); view.setanimation(alphaanimation); view.postinvalidate();` 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -