Created
April 8, 2014 09:29
-
-
Save Kuchinashi/10104248 to your computer and use it in GitHub Desktop.
半透明のActionBarを画面下に表示する ref: http://qiita.com/kuchinashi_r/items/254d8c7a9d5c58c362b8
This file contains hidden or 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 | |
android:id="@+id/rootLayout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@drawable/bg_1920x1080" /> |
This file contains hidden or 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.main_activity.xml); | |
getWindow().getDecorView().setBackgroundResource(R.drawable.bg_1920x1080); |
This file contains hidden or 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="Theme.MainActivity.ActionBar" parent="@android:style/Widget.Holo.ActionBar"> | |
<item name="android:background">#88ffffff</item> | |
</style> |
This file contains hidden or 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 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