1
2
3
4
5
6
7
8
9
10
|
boolean isTablet () {
int portrait_width_pixel=Math.min(this.getResources().getDisplayMetrics().widthPixels, this.getResources().getDisplayMetrics().heightPixels);
int dots_per_virtual_inch=this.getResources().getDisplayMetrics().densityDpi;
float virutal_width_inch=portrait_width_pixel/dots_per_virtual_inch;
if (virutal_width_inch <= 2) {
return false;
} else {
return true;
}
}
|
2014년 12월 2일 화요일
[android] 폰과 태블릿 구분
2014년 11월 18일 화요일
[android] textview에 이미지 넣기
setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom)
: 글씨의 왼쪽, 상단, 오른쪽, 아래에 이미지 추가
setCompoundDrawablePadding (int pad)
: 이미지와 글씨 사이의 간격 설정
1
2
3
4
|
TextView txtEvent = (TextView)convertView.findViewById(R.id.cell_event);
txtEvent.setCompoundDrawablesWithIntrinsicBounds(R.drawable.event, 0, 0, 0);
txtEvent.setCompoundDrawablePadding(10);
txtEvent.setText("이벤트합니다.");
|
2014년 11월 13일 목요일
[android] 네트워크 상태가 변경 될 때 마다 실시간 확인 방법. (BroadcastReceiver 사용)
네트워크가 변경되었을 때 실시간으로 앱에서 하고 싶은 동작을 할 수 있다.
[AndroidManifest.xml]
activity와 동등한 단계에 추가.
[appNetwork.java]
[java 파일]
[AndroidManifest.xml]
activity와 동등한 단계에 추가.
1
2
3
4
5
|
<receiver android:name = "appNetwork">
<intent-filter>
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"/>
</intent-filter>
</receiver>
|
[appNetwork.java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
public class appNetwork extends BroadcastReceiver {
private Activity activity;
public appNetwork() {
super();
}
public appNetwork(Activity activity) {
this.activity = activity;
}
@Override
public void onReceive(Context context, Intent intent) {
String action= intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
try {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
NetworkInfo _wifi_network =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(_wifi_network != null) {
// wifi, 3g 둘 중 하나라도 있을 경우
if(_wifi_network != null && activeNetInfo != null){
}
// wifi, 3g 둘 다 없을 경우
else{
}
}
} catch (Exception e) {
Log.i("ULNetworkReceiver", e.getMessage());
}
}
}
}
|
[java 파일]
1
2
3
|
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
appNetwork receiver = new appNetwork(this);
registerReceiver(receiver, filter);
|
참고
2014년 11월 12일 수요일
[ android ] actionbar 높이 변경
styles.xml에 아래 내용 추가.
actionbar높이를 변경하면 tab까지 동일하게 변경됨.
<item name="android:attr/actionBarSize">40dp</item>
actionbar높이를 변경하면 tab까지 동일하게 변경됨.
<item name="android:attr/actionBarSize">40dp</item>
2014년 11월 10일 월요일
[android] viewpager PagerAdapter 새로고침
notifyDataSetChanged를 해도 refresh가 안될 때 PagerAdapter에 아래 내용 추가하면 되
1
2
3
4
|
@Override
public int getItemPosition(Object item) {
return POSITION_NONE;
}
|
2014년 11월 5일 수요일
[android] fragment 에서 activity 함수 호출하기
[ Fragment ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// 3. ListFragment 에서 Activity 에 대한 참조
OnSelectedListener mListener;
// 1. ListFragment 내에 이벤트 인터페이스를 정의
public interface OnSelectedListener {
public void onDialogSelected();
}
// 3.ListFragment 에서 Activity 에 대한 참조
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener");
}
}
|
[Activity]
1
2
3
4
|
// 2.Activity 에서 Fragment 의 이벤트 인터페이스를 구현
public void onDialogSelected(){
showDialog();
}
|
ListFragment에서 호출을 원하는 곳에 다음과 같이 사용.
mListener.onDialogSelected();
추가하지 않을 경우 RuntimeException 발생.
[android] java에서 resource 값 가져오기.
res/values/color.xml파일에 등록된 색상 값 가져오는 방법.
1
2
3
|
int colorRed = getResources().getColor(R.color.blue);
TextView txtTest = (TextView)findViewById(R.id.txt1);
txtTest.setTextColor(colorRed);
|
피드 구독하기:
글 (Atom)