Last active
October 2, 2015 15:17
-
-
Save YO-LUN-CHIEN/70222a89cd6ccd24ffc2 to your computer and use it in GitHub Desktop.
Blogger Android Menu Resource
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
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/text" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/hello_world" /> | |
</RelativeLayout> |
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
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
final int id = item.getItemId(); | |
final TextView text = (TextView) super.findViewById(R.id.text); | |
if (id == R.id.item0) { | |
text.setEnabled(true); | |
return true; | |
} | |
else if (id == R.id.item1) { | |
text.setEnabled(false); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} |
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" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" /> | |
<item | |
android:id="@+id/item1" | |
android:title="Disable" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Monday" | |
app:showAsAction="always" /> | |
<item | |
android:id="@+id/item1" | |
android:title="Monday" | |
app:showAsAction="never" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Monday" | |
android:titleCondensed="Mon." | |
app:showAsAction="always" /> | |
<item | |
android:id="@+id/item1" | |
android:titleCondensed="Mon." | |
android:title="Monday" | |
app:showAsAction="never" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
android:titleCondensed="ABC..." | |
app:showAsAction="always"/> | |
<item | |
android:id="@+id/item1" | |
android:title="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
android:titleCondensed="ABC..." | |
app:showAsAction="never"/> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" | |
app:showAsAction="always" /> | |
<item | |
android:id="@+id/item1" | |
android:title="Disable" | |
app:showAsAction="ifRoom" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" | |
app:showAsAction="always" /> | |
<item | |
android:id="@+id/item1" | |
android:title="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
app:showAsAction="ifRoom" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" | |
app:showAsAction="ifRoom" /> | |
<item | |
android:id="@+id/item1" | |
android:title="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
app:showAsAction="always" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" | |
android:icon="@mipmap/ic_launcher" | |
app:showAsAction="ifRoom|withText" /> | |
<item | |
android:id="@+id/item1" | |
android:title="Disable" | |
app:showAsAction="never" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" | |
app:actionLayout="@layout/menu_layout" | |
app:showAsAction="ifRoom|collapseActionView" /> | |
<item | |
android:id="@+id/item1" | |
android:title="Disable" | |
app:showAsAction="never" /> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:icon="@mipmap/ic_launcher" | |
android:title="Enable" | |
app:showAsAction="ifRoom" /> | |
<item | |
android:id="@+id/item1" | |
android:icon="@mipmap/ic_launcher" | |
android:title="Disable" | |
app:showAsAction="never"/> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
app:actionLayout="@layout/menu_layout" | |
app:showAsAction="ifRoom" /> | |
<item | |
android:id="@+id/item1" | |
app:actionLayout="@layout/menu_layout" | |
app:showAsAction="never"/> | |
</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
<menu 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" | |
tools:context=".MainActivity"> | |
<item | |
android:id="@+id/item0" | |
android:title="Enable" | |
app:showAsAction="ifRoom" /> | |
<item | |
android:id="@+id/item1" | |
android:title="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
android:titleCondensed="ABC..." | |
app:showAsAction="ifRoom"/> | |
</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.dreammushrooms.blogger_menuresource; | |
import android.support.v7.app.ActionBarActivity; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.TextView; | |
public class MainActivity extends ActionBarActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
super.setContentView(R.layout.activity_main); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
super.getMenuInflater().inflate(R.menu.menu_main, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
final int id = item.getItemId(); | |
final TextView text = (TextView) super.findViewById(R.id.text); | |
if (id == R.id.item0) { | |
text.setEnabled(true); | |
return true; | |
} else if (id == R.id.item1) { | |
text.setEnabled(false); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment