Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Changing an alpha value of a LayerDrawable item , triggered by onClick event
    primarykey
    data
    text
    <p>a newbie question.</p> <p>I'm trying to change an <code>alpha value</code> of a <code>bitmap item</code> inside a <code>layer-list</code>.</p> <p>my <code>drawable xml</code> is as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item&gt; &lt;bitmap android:src="@drawable/img_btn" android:gravity="center"/&gt; &lt;/item&gt; &lt;item&gt; &lt;bitmap android:src="@drawable/image_frame" android:gravity="center"/&gt; &lt;/item&gt; &lt;/layer-list&gt; </code></pre> <p>my <code>MainActivity</code> is as follows:</p> <pre><code>public class MainActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MainApp.show(this); addListeners(); changeAlpha(128); } private void changeAlpha(int opc){ ImageView img = (ImageView) findViewById(R.id.img_A); LayerDrawable layer = (LayerDrawable) img.getDrawable(); BitmapDrawable bg = (BitmapDrawable) layer.getDrawable(0); bg.setAlpha(opc); } private void addListeners() { ImageView img = (ImageView) findViewById(R.id.img_A); View.OnClickListener imageAClickListener = new View.OnClickListener() { public void onClick(View view) { changeAlpha(255); } }; img.setOnClickListener(imageAClickListener); } public void onBackPressed() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(Definitions.CONFIRM_EXIT) .setCancelable(false) .setPositiveButton(Definitions.YES, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MainActivity.this.finish(); } }) .setNegativeButton(Definitions.NO, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } } </code></pre> <p>the first call to <code>changeAlpha</code> (from <code>onCreate</code>) works just fine, but when I call the method from the <code>click</code> event it does nothing (without failing)</p> <p>What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload