English 中文(简体)
为什么要叫PackgroundColor来打破其长点的彩色变化和强调?
原标题:Why does calling setBackgroundColor on a view break its long click color change and highlighting?

在安伯,当你长期点击一个清单项目时,从大颜色到白色,表明用户已将其搁置,将展示一个背景项目。 此外,你可以使用轨道球(或一些电话的箭 but子)选择清单项目,然后使用你的手法。

然而,我有一份清单,其内容是我所说的话,即这些预期行为不再奏效。 任何人都知道为何如此,如何确定?

注:在xml中确定背景颜色并不是一种选择,因为我需要能够动态地确定/改变肤色。

我的新意见功能如下:

@Override
public View newView(Context ctx, Cursor cursor, ViewGroup parent)
{
    View view = new View(mCtx);
    final LayoutInflater li = (LayoutInflater) mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = li.inflate(R.layout.task_list_item, null);

    return view;
}
最佳回答

否则,<代码>ListView有一个<编码>Selector,该编码将在你发布一个清单项目时使用<代码>可转让<<>代码>。 然而,如果您的列名观点具有坚实的背景,那么你就不能够看到选择者(或任何其他国家)的长效感,因为它属于清单项目的范围。

If you want to see the selector s longpress animation/selected/pressed state, then the list item s has to have a transparent background when the item is selected/pressed/longpressed. You can do it by using a StateListDrawable as your item s background instead of a solid color.

http://developer.android.com/fer/android/graphics/drawable/StateListDrawable.html。

public class ColorfulListItemDrawable extends StateListDrawable {
    private final PaintDrawable mColor;

    public ColorfulListItemDrawable(int color) {
        mColor = new PaintDrawable(color);
        initialize();
    }
    private void initialize() {
        Drawable color = mColor;
        Drawable selected = new ColorDrawable(Color.TRANSPARENT);
        addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled, 
                android.R.attr.state_window_focused}, selected);
        addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled, 
                android.R.attr.state_window_focused,android.R.attr.state_selected}, selected);
        addState(new int[] {android.R.attr.state_enabled,android.R.attr.state_window_focused, android.R.attr.state_selected}, selected);
        addState(new int[] {}, color);
    }
    public void setColor(int color) {
        mColor.getPaint().setColor(color);
        mColor.invalidateSelf();
    }   
}
问题回答

当你确定背景颜色时,你重压了假定的背景,似乎只是一种明显的动向。 如果你想有不同的颜色,你就不得不与你所希望的颜色混淆。

您希望创建一种与选定国家有关的<代码>Selector。

由于你可以使用XML解决办法,你希望创建rel=“nofollow”>。 ListView.setSelector。

这可能是因为你只是给布局打上了独有的颜色。 如果像缺席那样,它有像<条码>、List

如果你重新使用清单(可能就所有观点开展工作),则我有一条线解决办法。

For example:

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listID"
    android:drawSelectorOnTop="true"
    ...
/>




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签