我使用导航抽屉活动创建了导航抽屉。 我要做的就是在Fab上使用setonClicklistener。但是,它没有回应。我试图将其更改为Imageview& CircleImageView。
onclicklistener的java代码位于
之下 profnewfab = (FloatingActionButton) findViewById(R.id.profile_new);
if (profnewfab != null) {
profnewfab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
});
}
以下是我的nav_header_profile.xml的代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/navheaderbg"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:weightSum="1">
<android.support.design.widget.FloatingActionButton
android:id="@+id/profile_new"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:backgroundTint="#37474F"
android:src="@drawable/usericon_new" />
<android.support.v7.widget.CardView
android:alpha="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_marginTop="8dp"
android:id="@+id/susernametv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium" />
</android.support.v7.widget.CardView>
</LinearLayout>
答案 0 :(得分:0)
试试这个
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View header = navigationView.getHeaderView(0);
FloatingActionButton FloatingActionButton= (FloatingActionButton) header.findViewById(R.id.loatingActionButton);
FloatingActionButton.setOnclickListener(.....)