ImageButton の android:focusable="false" が動作しない
<ImageButton android:id="@+id/imageButton1" android:src="@drawable/icon" android:focusable="false" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
フォーカスが移動しないように、focusable="false" を設定してもフォーカスが移動してしまう。
でも、コードで設定するとうまくいみたい。
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewById(R.id.imageButton1).setFocusable(false); }
1.6 と 2.2 のどちらでも発生していた。
ImageViewのソースを確認したら...
public class ImageButton extends ImageView { public ImageButton(Context context) { this(context, null); } public ImageButton(Context context, AttributeSet attrs) { this(context, attrs, com.android.internal.R.attr.imageButtonStyle); } public ImageButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true); } @Override protected boolean onSetAlpha(int alpha) { return false; } }
うわぁ...。
でも、this() でコンストラクタ呼べるのは知らなかった。こりゃいいや。