Last active
December 16, 2015 19:49
-
-
Save daichan4649/5487682 to your computer and use it in GitHub Desktop.
custom actionbar
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="vertical" | |
android:paddingBottom="8dip" | |
android:paddingLeft="8dip" | |
android:paddingTop="8dip" > | |
<Button | |
android:id="@+id/button1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" | |
android:gravity="center_vertical" | |
android:text="Button" /> | |
</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
<LinearLayout 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:background="#ff0000" | |
android:padding="32dip" | |
android:orientation="vertical" > | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:background="@drawable/border" | |
android:padding="32dip" > | |
<Button | |
android:id="@+id/button2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_margin="32dip" | |
android:background="@drawable/selector_button" | |
android:text="shape" /> | |
</LinearLayout> | |
</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="CustomActionBarTestActivity" | |
android:label="@string/title_activity_custom_actionbar" | |
android:theme="@style/Theme.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
public class CustomActionBarTestActivity extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
initActionBar(); | |
} | |
private void initActionBar() { | |
// これでカスタムすると | |
// - themeで高さ変更OK | |
// Theme継承だとNG(actionbar未定義) | |
// Holo継承でactionbar表示、その後、android:actionBarSize をカスタムする。 | |
// android:windowTitleSize では反映されない。 | |
// (actionbarサイズはdimen内で直指定されてる) | |
// - カスタムビュー表示OK | |
// - actionItem表示OK | |
// という状態。 | |
setContentView(R.layout.activity_custom_actionbar); | |
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); | |
getActionBar().setCustomView(R.layout.actionbar); | |
findViewById(R.id.button1).setOnClickListener(new OnClickListener() { | |
public void onClick(View v) { | |
Toast.makeText(getApplicationContext(), "click", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
// これでカスタムすると | |
// - themeで高さ変更OK(Theme継承のみ。Theme.Holo.Light継承だと例外) | |
// - カスタムビュー表示OK | |
// - actionItem表示NG | |
// という状態。 | |
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); | |
// setContentView(R.layout.activity_main); | |
// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, | |
// R.layout.actionbar); | |
// findViewById(R.id.button1).setOnClickListener(new OnClickListener() { | |
// public void onClick(View v) { | |
// Toast.makeText(getApplicationContext(), "click", | |
// Toast.LENGTH_SHORT).show(); | |
// } | |
// }); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.activity_main, menu); | |
return true; | |
} | |
} |
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
<resources> | |
<style name="Theme.Custom" parent="android:Theme.Holo.Light"> | |
<!-- | |
これは効かない | |
<item name="android:windowTitleSize">150dip</item> | |
--> | |
<!-- dimens内に直指定してあるのでこれを変更する --> | |
<item name="android:actionBarSize">150dip</item> | |
<item name="android:actionBarStyle">@style/CustomActionBarStyle</item> | |
</style> | |
<style name="CustomActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar"> | |
<item name="android:background">#64ff0000</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment