开发者

how can I indicate selection in a clickable FrameLayout?

I am trying to implement a clickable composite view. The composite view is implemented using a FrameLayout which contains an inflated set of child views. If the user taps anywhere in the FrameLayout, I would like to flash the view as if it was selected, and then perform some action.

Here is my current code:

private void fillFrameLayout(FrameLayout frame) {
    View开发者_如何学编程 disclosureItem = getLayoutInflater().inflate(R.layout.disclosure_item, frame);
    frame.setClickable(true);
    frame.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
            // Do something
        }
    });
}

Can someone please tell me how I can provide some visible feedback to the user when they tap the frame? IE: select the frame in the same way that selection appears in a list or grid view.

Thanks.


You could define a background drawable with multiple drawables:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
      android:state_window_focused="true"
      android:drawable="@drawable/bg_selected" />

<item android:state_focused="true"
      android:state_window_focused="true"
      android:drawable="@drawable/bg_selected" />

<item android:state_selected="true"
      android:state_window_focused="true"
      android:drawable="@drawable/bg_selected />

<item android:drawable="@drawable/bg" />

In your layout, add this drawable as a background drawable:

<FrameLayout
    ...
    android:background="@color/bg_drawable" >

I hope this is what you meant?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜