Last active
December 19, 2015 23:59
-
-
Save daichan4649/6037888 to your computer and use it in GitHub Desktop.
custom actionbar (for Android)
MenuFragment 動的切替
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="horizontal"> | |
<ImageButton | |
android:id="@+id/back" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" /> | |
<TextView | |
android:id="@+id/title" | |
android:layout_width="0dip" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:gravity="center_vertical" | |
android:text="Title" | |
android:textColor="#FFFFFF" /> | |
</LinearLayout> |
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
<activity | |
android:name=".XxxActivity" | |
android:theme="@style/Custom" /> |
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
<style name="Custom" parent="android:Theme.Holo.Light"> | |
<!-- actionbar全体 --> | |
<item name="android:actionBarStyle">@style/Custom.ActionBarStyle</item> | |
<!-- actionItem --> | |
<item name="android:actionMenuTextColor">#FFFFFF</item> | |
</style> | |
<style name="Custom.ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar"> | |
<item name="android:background">@drawable/color_title</item> | |
<item name="android:titleTextStyle">@style/Custom.ActionBarStyle.TitleTextStyle</item> | |
</style> | |
<style name="Custom.ActionBarStyle.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title"> | |
<item name="android:textColor">#FFFFFF</item> | |
</style> |
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 void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_xxx); | |
// actionbar | |
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); | |
getActionBar().setCustomView(R.layout.actionbar); | |
findViewById(R.id.back).setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
} | |
}); | |
// menu動的表示(show/hide で切替) | |
MenuFragment menuFragment = null; | |
if (getFragmentManager().findFragmentByTag("menu") == null) { | |
menuFragment = new MenuFragment(); | |
} | |
FragmentTransaction ft = getFragmentManager().beginTransaction(); | |
ft.add(menuFragment, "menu"); | |
ft.commit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment