2017-09-04 107 views
-1

enter image description here工具栏ImageView的不clickabele

这是含有fragmelayout其中我将在的博客,提示和论坛按钮点击添加片段的片段的图像。我已经包含了一个工具栏xml顶部两个图像。问题是我得到的按钮点击,但没有包括工具栏imageview点击。任何解决方案

工具栏:

<?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> 

这是常见的工具栏的代码。

布局:

<?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> 

在onActivityCreated设置onClickListener后insted的butterknife注射的我正在上搜索图标点击,但不是在后面的图标。我已经在某些片段中切换了背部图标的可见性。这是在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

发表了一段代码让我们可以看一下 –

+0

@AkshayKatariya请看看 –

+0

也是你的点击监听器的java代码.. –

回答

0

我得到了答案。其实我并没有把这些新的碎片添加到叠堆中,因此叠堆是空的,所以它不会回来。