2014-02-27 3 views
1

Android 애플리케이션의 알림 영역에 아이콘을 설정하려고합니다.알림 영역에 아이콘을 올바르게 설정하는 방법?

나는 티커의 아이콘이 잘린 것처럼 보였다. 티커가 사라지면 알림 영역에있는 아이콘이 잘 보입니다. 내 알림 내 사용자 지정 레이아웃

여기
String msg = "Calculation completed. Tap to view result."; 
final Intent restartActivityIntent = new Intent(context, NumberOfPrimesActivity.class); 
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, restartActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
RemoteViews mContentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification); 
mContentView.setImageViewResource(R.id.image, R.drawable.two); 
mContentView.setTextViewText(R.id.text, msg); 
Notification.Builder notificationBuilder = new Notification.Builder(context).setSmallIcon(R.drawable.two).setContentTitle("Sum of Primes").setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent).setTicker(msg); 
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
manager.notify(NOTIFICATION_ID, notificationBuilder.build()); 

입니다 : : 여기 아이콘을 설정 내 코드는

여기
<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/toast_layout_root" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#7777" 
     android:padding="3dp"> 

     <ImageView android:id="@+id/image" 
     android:layout_width="44dp" 
     android:layout_height="44dp" 
     android:layout_marginRight="10dp" 
     android:contentDescription="alert" 
     android:src="@drawable/two" /> 

     <TextView 
     android:id="@+id/text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#FFF" 
     android:textSize="24sp" /> 

    </LinearLayout> 

res 디렉토리는 모양을 같은 :

enter image description here

ldpi 폴더에있는 two.png 파일의 크기는 22x22입니다.

마지막으로 두 개의 스크린 샷이 있습니다. 첫 번째 아이콘이 잘린 상태로 티커가 표시됩니다. 두 번째 아이콘은 티커가 사라진 후에 아이콘을 보여줍니다. 아이콘은 두 번째 스크린 샷에서 잘 보입니다.

enter image description here enter image description here

업데이트

mdpi 폴더에있는 two.png 파일의 경우 48x48이입니다.

파일의 hdpi 폴더는 72x72입니다.

xhdpi 폴더의 two.png 파일의 크기는 92x92입니다.

폴더의 two.png 파일은 144x144입니다.

시뮬레이터를 사용하여 프로그램을 테스트하고 있습니다. 두 개의 시뮬레이터가 있습니다. 하나는 Nexus 7 (800 x 1280)이고 다른 하나는 Nexus 4 (768 x 1280)입니다.

두 시뮬레이터 모두에서 티커의 아이콘이 잘립니다.

+0

스크린 샷에서 기기의 화면 밀도는 얼마입니까? 다른 폴더의 two.png 차원은 무엇입니까? – TactMayers

+0

방금 ​​내 질문을 업데이트했습니다. –

답변

4

어떤 이유로 든 티커보기의 아이콘은 자동으로 크기가 조정되지 않지만 알림보기에는 표시됩니다.

Android Iconography에 따르면 "알림 아이콘은 24x24 dp이어야합니다."

LDPI : 18 X 18px
MDPI : 24 X 24 픽셀
hdpi에 36 X 36 픽셀의
xhdpi : 48 X 48px

그래서, 크기 조정하는 경우 two.png 다른 화면 밀도의 다음 측정으로 변환, 아이콘이 res 폴더에 있으면 아이콘이 티커 및 알림보기에서 잘리지 않습니다.

관련 문제