Ceci est l'image d'un fragment contenant un fragmelayout où je vais ajouter des fragments sur les clics de bouton de blog, Conseils et forums. J'ai inclus une barre d'outils xml en haut avec deux images. Le problème est que j'obtiens des clics de bouton mais pas des clics d'imageview de barre d'outils inclus. Des solutions?
Barre d'outils:
<?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>
Voici le code barre d'outils commune.
Mise en page:
<?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>
Après avoir réglé onClickListener dans onActivityCreated insted d'injection de Butterknife Je reçois des clics sur la recherche icône, mais pas sur l'icône en arrière. J'ai basculé la visibilité de l'icône arrière dans quelques fragments. C'est un fragment avec d'autres fragments chargeant dans les catégories de fl.
Code de 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();
}
});
Toast est INTERVENUES mais pas un autre.
poster un peu de code afin que nous puissions regarder dans –
@AkshayKatariya s'il vous plaît jeter un oeil –
aussi le code java pour votre écouteur de clic .. –