Tag: support library

如何获得在RecyclerView中select的位置?

我正在试验支持库的recyclerview和卡片。 我有一个卡的recyclerview。 每张卡片的右上angular都有一个“x”图标可以将其删除: 卡xml, list_item.xml : <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/taskDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:textSize="40sp" android:text="hi"/> <ImageView android:id="@+id/xImg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:src="@drawable/ic_remove"/> </RelativeLayout> </android.support.v7.widget.CardView> 我试图用我将在notifyItemRemoved(position)中的notifyItemRemoved(position)中使用的位置来标记行: public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.TaskViewHolder> { private List<Task> taskList; private TaskAdapter thisAdapter = this; // cache of views to reduce number […]

当使用CoordinatorLayout时,我的ScrollView的大小不正确

我在布局中使用ScrollView,并试图从devise支持库中使用新的CoordinatorLayout 。 我的布局文件如下所示: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> … </LinearLayout> </ScrollView> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar … /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 当testing这个滚动视图只占据屏幕的一部分。 什么地方出了错?

在底部工作表中禁用用户拖动

我正试图禁用用户在BottomSheet拖动。 我想禁用的原因是两件事。 1.防止ListView向下滚动,2.我不希望用户使用拖动,而是使用BottomSheetView上的button。 这就是我所做的 bottomSheetBehavior = BottomSheetBehavior.from(bottomAnc); bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_EXPANDED) { //Log.e("BottomSheet", "Expanded"); } else if (newState == BottomSheetBehavior.STATE_COLLAPSED) { //Log.e("BottomSheet", "Collapsed"); } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { // React to dragging events bottomSheet.setOnTouchListener(new View.OnTouchListener() { @Override […]

支持库23.1.1中的AppBarLayout.setExpanded(boolean,true)奇怪的animation

在我的应用程序中,我使用setExpanded(boolean, true)在特定事件上展开或收缩AppBarLayout 。 我有一个很好的结果,用com.android.support:design:23.1.0一个活泼和stream畅的animation,然后我更新到23.1.1和animation变得非常缓慢,不活泼。 在android.support.design.widget.AppBarLayout的源代码中,我将问题定位在animateOffsetTo (在public static class Behavior extends HeaderBehavior<AppBarLayout> ),在版本23.1.0中是这样的: private void animateOffsetTo(final CoordinatorLayout coordinatorLayout, final AppBarLayout child, int offset) { if (mAnimator == null) { mAnimator = ViewUtils.createAnimator(); mAnimator.setInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR); mAnimator.setUpdateListener(new ValueAnimatorCompat.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimatorCompat animator) { setHeaderTopBottomOffset(coordinatorLayout, child, animator.getAnimatedIntValue()); } }); } else { mAnimator.cancel(); } mAnimator.setIntValues(getTopBottomOffsetForScrollingSibling(), offset); mAnimator.start(); } […]

使用带有内部CoordinatorLayout的BottomSheetBehavior

devise支持库BottomSheetBehavior介绍了BottomSheetBehavior ,它允许一个协调器的孩子充当最底层(从屏幕底部可以拖动的视图)。 我想要做的是, 作为底部视图 ,有以下视图(典型的协调员+崩溃的东西): <CoordinatorLayout app:layout_behavior=“@string/bottom_sheet_behavior”> <AppBarLayout> <CollapsingToolbarLayout> <ImageView /> </CollapsingToolbarLayout> </AppBarLayout> <NestedScrollView> <LinearLayout> < Content … /> </LinearLayout> </NestedScrollView> </CoordinatorLayout> 不幸的是,底部视图应该实现嵌套滚动,否则他们不会得到滚动事件。 如果您尝试使用主要活动,然后将此视图作为底部表单加载,则会看到滚动事件仅作用于“纸张”上,出现了一些奇怪的行为,您可以看到是否继续阅读。 我很确定这可以通过inheritanceCoordinatorLayout来处理,或者通过BottomSheetBehavior 。 你有什么提示吗? 一些想法 应该使用requestDisallowInterceptTouchEvent()来在某些情况下从父requestDisallowInterceptTouchEvent()中窃取事件: 当AppBarLayout偏移量> 0时 当AppBarLayout偏移量是== 0,但我们正在滚动(想一下,你会看到) 第一个条件可以通过设置OnOffsetChanged到内部的应用程序栏获得; 第二个需要一些事件处理,例如: switch (MotionEventCompat.getActionMasked(event)) { case MotionEvent.ACTION_DOWN: startY = event.getY(); lastY = startY; userIsScrollingUp = false; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: userIsScrollingUp […]

如何设置支持库零食栏文本颜色的东西比android:textColor?

所以我开始在devise支持库中使用新的Snackbar,但是我发现当你在主题中定义“android:textColor”时,它适用于快餐栏的文本颜色。 这显然是一个问题,如果您的主要文字颜色是黑暗的。 有没有人知道解决这个问题的方法,或者如何为我的文字涂色? 编辑2017年1月:(回答后) 虽然有一些自定义的解决scheme可以解决以下问题,但为主题Snackbars提供正确的方法可能也不错。 首先,你可能不应该在你的主题中定义android:textColor (除非你真的知道使用主题的范围)。 这设置基本上连接到您的主题的每个视图的文本颜色。 如果要在视图中定义不是默认的文本颜色,请使用android:primaryTextColor并在您的自定义视图中引用该属性。 但是,要将主题应用于Snackbar ,请参考第三方材料文档中的质量指南: http : //www.materialdoc.com/snackbar/ (按照程序化主题实现,不要依赖xml样式) 以供参考: // create instance Snackbar snackbar = Snackbar.make(view, text, duration); // set action button color snackbar.setActionTextColor(getResources().getColor(R.color.indigo)); // get snackbar view View snackbarView = snackbar.getView(); // change snackbar text color int snackbarTextId = android.support.design.R.id.snackbar_text; TextView textView = (TextView)snackbarView.findViewById(snackbarTextId); textView.setTextColor(getResources().getColor(R.color.indigo)); // change […]

NestedScrollView内的Recycler视图使滚动在中间开始

当我在NestedScrollView中添加一个RecyclerView时,我得到了一个奇怪的滚动行为。 会发生什么情况是,只要滚动视图的行数比屏幕上显示的行数多,一旦活动启动,NestedScrollView就会从顶部(图1)开始偏移。 如果滚动视图中的项目很less,以便它们都可以一次显示,则不会发生(图2)。 我正在使用支持库的版本23.2.0。 图1 :错误 – 从顶部偏移开始 图2 :正确 – 回收站视图中的几件物品 我粘贴在我的布局代码下面: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="fill_vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Title:" style="@style/TextAppearance.AppCompat.Caption"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/bodyPadding" style="@style/TextAppearance.AppCompat.Body1" android:text="Neque porro quisquam est qui dolorem ipsum"/> <TextView android:layout_width="match_parent" […]

创buildActionMode时不会调用onPrepareActionMode

我刚刚完成了一个我的应用程序调整到新的v22.1.1支持&appcompat库,看到这里和这里的更多细节。 当我做了一些testing的时候,我正在使用ActionModes 。 使用startSupportActionMode()调用启动ActionMode时 – 使用现在不推荐使用的ActionBarActivity基类或新的AppCompatActivity基类时onPrepareActionMode() – onPrepareActionMode()没有被调用。 在以前的版本中,包括v21.0.3和v22.0.0,当ActionMode最初使用startSupportActionMode()创build时,会自动调用startSupportActionMode() 。 我在2.2,4.0.2和5.0版本的设备上testing过,所以它不是版本依赖的。 有没有人知道,如果这是意向的行为,这是在v22.1.1引入,或一个错误? 我发现这个问题 ,但是这里没有太多的反馈 2015年5月11日编辑: 正如Android问题追踪器159527中提到的,这个问题不仅影响到appcompat的v22.1.x和支持库,还影响到了5.1 Android的实现。 目前有两种可能的临时解决scheme, @Override public ActionMode startSupportActionMode(final ActionMode.Callback callback) { // Fix for bug https://code.google.com/p/android/issues/detail?id=159527 final ActionMode mode = super.startSupportActionMode(callback); if (mode != null) { mode.invalidate(); } return mode; } 和一个“快速和肮脏的”(当你实例化你的ActionMode): final ActionMode actionMode = startSupportActionMode(new MyActionMode()); if(actionMode != null) […]

android-support-v7-appcompat和android-support-v4之间的区别

我想知道android-support-v4.jar和android-support-v7-appcompat.jar的区别 。 如果我想在我的应用程序中添加appcompat Action Bar,我需要添加android-support-v7-appcompat.jar和android-support-v4.jar,或者只添加android-support-v7-appcompat.jar 。 另外, android-support-v13.jar是否有appcompat?

使用SpanSizeLookup在GridLayoutManager中设置项目的范围

我想用节标题来实现网格状的布局。 想想https://github.com/TonicArtos/StickyGridHeaders 我现在应该做什么: mRecyclerView = (RecyclerView) view.findViewById(R.id.grid); mLayoutManager = new GridLayoutManager(getActivity(), 2); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch(mAdapter.getItemViewType(position)){ case MyAdapter.TYPE_HEADER: return 1; case MyAdapter.TYPE_ITEM: return 2; default: return -1; } } }); mRecyclerView.setLayoutManager(mLayoutManager); 现在,常规项目和标题的跨度大小都是1.我该如何解决这个问题?