-1
ツールバーImageViewのこれは、私がブログ、ヒントとフォーラムのボタンのクリックにフラグメントを追加しますfragmelayoutを含む断片のイメージです
clickabeleません。私は2つのimageviewsと上部にツールバーXMLを含めている。問題は、ボタンのクリックを取得していますが、ツールバーの画像ビューのクリックは含まれていません。どんな解決策ですか?
ツールバー:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
tools:ignore="MissingPrefix"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/header_gray"
android:focusable="true"
>
<ImageView
android:id="@+id/imgHomeToolbarBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:contentDescription="@string/app_name"
android:padding="10dp"
android:src="@drawable/left_arrow"
android:focusable="true"
/>
<TextView
android:id="@+id/txtHomeToolbarBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/imgHomeToolbarBack"
android:contentDescription="@string/app_name"
android:text="@string/edit"
android:textColor="@android:color/black"
android:textSize="@dimen/font_medium_semi"
fontPath="@string/font_regular"
/>
<TextView
android:id="@+id/txtHomeToolbarLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/app_name"
android:textColor="@android:color/black"
android:textSize="@dimen/text_size_20"
/>
<ImageView
android:id="@+id/imgHomeToolbarCalendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/dimen_margin_5"
android:contentDescription="@string/app_name"
android:padding="10dp"
android:src="@drawable/calender"
android:text="@string/next"
android:focusable="true"
android:textColor="@color/darkGrey"
android:textStyle="normal"
/>
</RelativeLayout>
</LinearLayout>
これは、一般的なツールバーのコードです。
レイアウト:onActivityCreatedにonClickListener設定した後
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="MissingPrefix"
>
<include
layout="@layout/toolbar_home"
android:id="@+id/toolbar"
/>
<LinearLayout
android:id="@+id/llCommunitySections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
>
<Button
android:id="@+id/btnBlog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="@string/nabta_blog"
style="?android:attr/buttonBarButtonStyle"
fontPath="@string/font_regular"
android:textColor="@color/textDarkBlue"
/>
<Button
android:id="@+id/btnHints"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="@string/hints_tips"
style="?android:attr/buttonBarButtonStyle"
fontPath="@string/font_regular"
android:textColor="@color/blogGreyText"
/>
<Button
android:id="@+id/btnForums"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="@string/forums"
style="?android:attr/buttonBarButtonStyle"
fontPath="@string/font_regular"
android:textColor="@color/blogGreyText"
/>
</LinearLayout>
<FrameLayout
android:id="@+id/flCategories"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
は、私が検索アイコン上ではなく、バックアイコンのクリックを取得していますbutterknife注射のinsted。私はいくつかの断片の裏アイコンの可視性をトグルしました。これは、flCategoriesにロードする他のフラグメントを含むフラグメントです。
OnClickListenerのコード:
imgHomeToolbarBack.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v)
{
getChildFragmentManager().popBackStack();
}
});
imgHomeToolbarCalendar.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v)
{
Toast.makeText(getActivity(), "Search Clicked", Toast.LENGTH_SHORT).show();
}
});
トーストが発生しているではなく、他の1。
私たちはそれを調べることができるので、 –
@AkshayKatariyaご覧ください –
あなたのクリックリスナーのためのJavaコード.. –