Created
September 7, 2014 08:49
-
-
Save s-shin/e02bd59ebbfa340854e0 to your computer and use it in GitHub Desktop.
Hotentorで使ったViewユーティリティから一部抜粋。
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
| package jp.hateblo.shin.hotentor.util; | |
| import android.annotation.TargetApi; | |
| import android.graphics.drawable.Drawable; | |
| import android.os.Build; | |
| import android.util.TypedValue; | |
| import android.view.View; | |
| import jp.hateblo.shin.hotentor.App; | |
| /** | |
| * Created by shin on 2014/08/30. | |
| */ | |
| public class ViewUtil { | |
| public static final int dip2px(int dip) { | |
| return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, | |
| App.getAppContext().getResources().getDisplayMetrics()); | |
| } | |
| public static final int getScreenWidth() { | |
| return App.getAppContext().getResources().getDisplayMetrics().widthPixels; | |
| } | |
| public static final int getScreenHeight() { | |
| return App.getAppContext().getResources().getDisplayMetrics().heightPixels; | |
| } | |
| // http://stackoverflow.com/a/11947755 | |
| @TargetApi(Build.VERSION_CODES.JELLY_BEAN) | |
| @SuppressWarnings("deprecation") | |
| public static void setViewBackground(View view, Drawable bg) { | |
| int sdk = android.os.Build.VERSION.SDK_INT; | |
| if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { | |
| view.setBackgroundDrawable(bg); | |
| } else { | |
| view.setBackground(bg); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment