gpt4 book ai didi

android - FloatingActionButton OnClickListener 不工作

转载 作者:行者123 更新时间:2023-11-29 00:03:51 25 4
gpt4 key购买 nike

从来没有错误。但是,您可以在动画中看到它被点击了。从父 Activity 为 MyMainActivity 的子 Activity 调用 Java 代码。

我还将包括该项目的 github,以防有人想尝试它。

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fav_button);

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Log.v("CLICKED","");
}
});

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lopic.movies.DetailActivity">

<android.support.v4.widget.NestedScrollView
android:id="@+id/activity_detail"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/original_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.SearchResult.Title"
android:textSize="24sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView
android:id="@+id/poster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:adjustViewBounds="true" />

<LinearLayout

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="5dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/vote_avg"
android:textAppearance="@android:style/TextAppearance.Medium" />

<TextView
android:id="@+id/vote_avg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/release_date"
android:textAppearance="@android:style/TextAppearance.Medium" />

<TextView
android:id="@+id/release_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/trailer_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="5dp"
android:text="Watch Trailer" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Overview"
android:textAppearance="@android:style/TextAppearance.Medium" />

<TextView
android:id="@+id/overview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fav_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_favorite_border_white_24px"
android:clickable="true"/>

</android.support.design.widget.CoordinatorLayout>

最佳答案

以编程方式将 FAB 置于最前面也应该可行:

FloatingActionButton fab = (FloatingActionButton) 
findViewById(R.id.fab);
fab.bringToFront();
fab.setOnClickListener... //etc

关于android - FloatingActionButton OnClickListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41492224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com