<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pingyijinren.helloworld"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:logo="@mipmap/twitter" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
package com.pingyijinren.helloworld; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button button; private ActionBar actionBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); actionBar = getSupportActionBar(); actionBar.setDisplayShowHomeEnabled(true); actionBar.setLogo(R.mipmap.twitter); actionBar.setDisplayUseLogoEnabled(true); button=(Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(actionBar.isShowing()){ actionBar.hide(); } else{ actionBar.show(); } } }); } }