Мне нужно настроить календарь, имеющий функцию сворачивания представления месяца к представлению недели. Я использую MaterialCalendarView
Библиотека для этого. Для этого я взял кадр, имеющий MaterialCalendarView
в качестве нижнего слоя и CollapsingToolbarLayout
в качестве прозрачного вида. Теперь проблема в том, что я не могу использовать мой CalendarView, так как это нижний слой и отключить прикосновение CollapsingToolbarLayout
.
Я попытался установить android:clickable="false"
из CoodinatorLayout
и всех его дочерних элементов, а также попытался использовать: collapsingToolbarLayout.setEnabled(false);
и установить для прослушивателя касания значение false, но безуспешно.
Это мой XML-файл:
-----some code-----
---
--
-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
app:mcv_allowClickDaysOutsideCurrentMonth="false"
app:mcv_firstDayOfWeek="monday"
app:mcv_tileHeight="36dp" />
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:focusedByDefault="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:focusedByDefault="false">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:focusedByDefault="false"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/dummy_toolbar"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@android:color/transparent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:focusedByDefault="false"
android:visibility="invisible"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin">
<View
android:id="@+id/dummy_toolbar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:focusedByDefault="false" />
</android.support.v7.widget.Toolbar>
<View
android:id="@+id/transparent_view"
android:layout_width="match_parent"
android:layout_height="252dp"
android:background="@android:color/transparent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:focusedByDefault="false" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_dark_gray"
android:fillViewport="true"
android:scrollbars="none"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_occasions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false" />
<TextView
android:id="@+id/txt_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/dp_50"
android:layout_marginTop="@dimen/dp_30"
android:layout_marginEnd="@dimen/dp_50"
android:layout_marginBottom="@dimen/dp_100"
android:background="@drawable/btn_gradient_bg"
android:fontFamily="@font/poppins_semibold"
android:gravity="center"
android:padding="@dimen/dp_16"
android:text="@string/next"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="@dimen/btn_text_size" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
И вот что я делаю в Java-файле:
collapsingToolbarLayout.setEnabled(false);
dummyToolbarView.setEnabled(false);
appBarLayout.setEnabled(false);
coordinatorLayout.setEnabled(false);
collapsingToolbarLayout.setOnTouchListener((v, event) -> {
calendarView.dispatchTouchEvent(event);
return false;
});
appBarLayout.setOnTouchListener((v, event) -> {
calendarView.dispatchTouchEvent(event);
return false;
});
coordinatorLayout.setOnTouchListener((v, event) -> {
calendarView.dispatchTouchEvent(event);
return false;
});
transparentView.setOnTouchListener((v, event) -> {
calendarView.dispatchTouchEvent(event);
return false;
});
dummyToolbarView.setOnTouchListener((v, event) -> {
calendarView.dispatchTouchEvent(event);
return false;
});
collapsingToolbarLayout.setClickable(false);
coordinatorLayout.setClickable(false);
appBarLayout.setClickable(false);
transparentView.setClickable(false);
После отключения касания всех видов все еще вызывается onClick, поэтому у меня также отключено нажатие.
Благодаря этому я могу обрабатывать прикосновение к MaterialCalendarView
, когда оно находится в свернутом режиме, но когда оно развернуто, я не могу его использовать, какой-то другой вид принимает щелчок.
Пожалуйста, помогите мне с этим. Я хочу получить доступ к MaterialCalendarView
touch и отключить касание видов внутри CoordinatorLayout
кроме NestedScrollView
.
Заранее спасибо.