2017-03-14 9 views
-2

を私はナビゲーションドロワーの内部リンクと画像を追加したい、ナビゲーション引き出し内の画像を追加する - アンドロイド

ナビゲーション引き出し内の画像を追加することが可能ですか?

私はこのようなコーディングを追加しかし、それはエラーの下に表示された引き出しナビゲーション内のリストビューを作成

ImageView imageView6 = (ImageView) findViewById(R.id.imageView6); 
     imageView6.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 



       specialOffers = (WebView) findViewById(R.id.specialOffers); 
       specialOffers.getSettings().setJavaScriptEnabled(true); 
       specialOffers.loadUrl("http://www.fbcdubai.com/membership/offres-privileges/"); 
      } 
      }); 


    } 

enter image description here

答えて

1

を確認してください、その後、最終的にそれを添付した画像ビューとカスタム項目を作成カスタムアダプター

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/***" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/***" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
      <include layout="@layout/****" 
       android:id="@+id/nav" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 
      <ListView 
       android:id="@+id/***" 
       android:layout_height="match_parent" 
       android:layout_width="match_parent" 
       /> 
     </LinearLayout> 
    </android.support.design.widget.NavigationView> 

cust item 

    enter code here 
    <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="8dp" 
    android:background="#00000000"> 

    <ImageView 
      android:id="@+id/****" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 

    <TextView 
     android:id="@+id/****" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     /> 

</LinearLayout> 
+0

私はあなたのコードを使用し、その作業イメージを編集しました。この画像にクリックイベントを作成する方法を教えてください。私はこの質問にマイナスの評価を持っているので私は新しい質問をすることができません@Syrine BOUSLIMI –

2

open nav_header_layout_name.xml年齢)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/nav_head" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="@drawable/side_nav_bar" 
    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"> 

    <ImageView 
     android:id="@+id/home_profile_image" 
     android:layout_width="120dp" 
     android:layout_height="170dp" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:layout_gravity="center" 
     android:src="@drawable/profile_image"/> 

</LinearLayout> 

Javaクラスからこの画像ビューにアクセスするには:
- 確かにあなたがgetViewメソッドの内部で、あなたのイメージにリスナーを設定することでこれを行うことができますImageView ProfileImage = (ImageViwe) hView.findViewById(R.id.home_profile_image);

+0

私は上記の答えを使用して画像を得たanswer.butに感謝します。その画像にクリックイベントを発生させる方法を教えていただけますか?私は新しい質問をすることができませんbcozこの質問はマイナスのランクを持っています..あなたが嘆願することができる場合 –

+1

ProfileImage .setOnClickListener(new View.OnClickListener(){ @Override パブリックボイドonClick(ビューv){ // YOUR_ACTION } }); – Badr

1

からNavigationView navigationView = findViewById(R.id.nav_view_id);
- View hView = navigationView.getHeaderView(0);
をアダプターのメソッド

discu.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

//ここに入れてくださいコード

});

+0

こんにちはthnks私はあなたのコードを追加しましたが、それはエラーを表示しています問題をチェックしてください私はあなたが@Syrineブッシュリム –

+0

あなたがエラーを投稿することができますか? –

関連する問題