Skip to content

Instantly share code, notes, and snippets.

@Kuchinashi
Created April 8, 2014 09:29
Show Gist options
  • Save Kuchinashi/10104248 to your computer and use it in GitHub Desktop.
Save Kuchinashi/10104248 to your computer and use it in GitHub Desktop.
半透明のActionBarを画面下に表示する ref: http://qiita.com/kuchinashi_r/items/254d8c7a9d5c58c362b8
<RelativeLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_1920x1080" />
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity.xml);
getWindow().getDecorView().setBackgroundResource(R.drawable.bg_1920x1080);
<style name="Theme.MainActivity.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">#88ffffff</item>
</style>
public class Utils {
private static final String TAG = Utils.class.getSimpleName();
/**
* ActionBarを画面下部に表示する
*
* @param activity
*/
public final static void actionBarUpsideDown(Activity activity) {
View root = activity.getWindow().getDecorView();
View firstChild = ((ViewGroup) root).getChildAt(0);
if (firstChild instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) firstChild;
List<View> views = findViewsWithClassName(root,
"com.android.internal.widget.ActionBarContainer");
if (!views.isEmpty()) {
for (View vv : views) {
viewGroup.removeView(vv);
}
for (View vv : views) {
viewGroup.addView(vv);
}
}
} else {
Log.e(TAG, "first child is not ViewGroup.");
}
}
private static List<View> findViewsWithClassName(View v, String className) {
List<View> views = new ArrayList<View>();
findViewsWithClass(v, className, views);
return views;
}
@SuppressWarnings("unchecked")
private static <T extends View> void findViewsWithClass(View v, String clazz, List<T> views) {
if (v.getClass().getName().equals(clazz)) {
views.add((T) v);
}
if (v instanceof ViewGroup) {
ViewGroup g = (ViewGroup) v;
for (int i = 0; i < g.getChildCount(); i++) {
findViewsWithClass(g.getChildAt(i), clazz, views);
}
}
}
private Utils() {
// ignore
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment