20160907

//MainActivity.java

 

import android.app.Activity;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.support.v7.widget.Toolbar;

import android.view.View;

import android.widget.Toast;

 

public class MainActivity extends Activity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

 

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        toolbar.setNavigationIcon(R.drawable.abc_ic_star_black_16dp);

        toolbar.setTitle("My ToolBar");

 

        // アイコンがタップされたときの処理

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override

                public void onClick(View v) {

                    Toast.makeText(getApplicationContext(),"Hello", Toast.LENGTH_SHORT).show();

            }

        });

 

 

    }}

 

--------------

 

//activity_main.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

 

    <!-- ToolBarを定義 -->

    <android.support.v7.widget.Toolbar

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:minHeight="?attr/actionBarSize"

        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

        android:id="@+id/toolbar"

        android:background="#d6e26b" />

</RelativeLayout>