Last active
December 18, 2015 19:49
-
-
Save slightfoot/5835584 to your computer and use it in GitHub Desktop.
Action Button with no padding example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<menu xmlns:android="http://schemas.android.com/apk/res/android" > | |
<item | |
android:id="@+id/action_share" | |
android:showAsAction="ifRoom" | |
android:icon="@android:drawable/ic_menu_share" | |
android:title="@string/action_share" | |
android:actionViewClass="com.example.actionbutton.ActionButton" | |
/> | |
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.actionbutton; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.Toast; | |
public class MainActivity extends Activity | |
{ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) | |
{ | |
getMenuInflater().inflate(R.menu.main, menu); | |
((ActionButton)menu.findItem(R.id.action_share) | |
.getActionView()).setMenuData(menu, R.id.action_share); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) | |
{ | |
if(item.getItemId() == R.id.action_share){ | |
Toast.makeText(this, "Got a click", Toast.LENGTH_SHORT).show(); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment