2016-07-15 14 views

答えて

0
 For Back Button: 
     1)Without using Toolbar 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     2)With Toolbar 
     Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar_gas_station); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 


    For Icon: 
     1)Without using Toolbar 
     You have to make menu file for this and then Override onOptionsItemSelected and onCreateOptionsMenu then write your code accordingly 

     2)With Toolbar: 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/app_bar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:fitsSystemWindows="true"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar_gas_station" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" > 
    <LinearLayout 
     android:id="@id/ll_header_find_parking_map" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:gravity="right" 
     android:padding="@dimen/fifteen"> 
     <ImageView 
      android:id="@+id/iv_search_find_parking_map" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:src="@drawable/search"/> 
    </LinearLayout> 
</android.support.v7.widget.Toolbar> 
</android.support.design.widget.AppBarLayout> 

    You can handle the click event as we do in normal ImageView. 
関連する問題