0
A
答えて
1
これはバッジと呼ばれます。 このライブラリをバッジサポートに使用できます。 Leolin Shortcut Badger これはまたAndroid ActionItem Badged 私はそれがすべてのデバイスでは不可能だと思います。三星はそれを使用しました。 ここではPostsはあなたと同じように見えます。アイコンするバッジを追加したい場合は
1
は
BadgeDrawableは、カスタム描画可能
package com.wisilica.cms.utitlty.viewHelper;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import com.wisilica.cms.R;
/**
* Created by Godwin Joseph on 02-11-2016 11:49 for Cms_Android application.
*/
public class BadgeDrawable extends Drawable {
private Paint mBadgePaint;
private Paint mBadgePaint1;
private Paint mTextPaint;
private Rect mTxtRect = new Rect();
private String mCount = "";
private boolean mWillDraw;
public BadgeDrawable(Context context) {
float mTextSize = context.getResources().getDimension(R.dimen.badge_text_size);
mBadgePaint = new Paint();
mBadgePaint.setColor(Color.RED);
mBadgePaint.setAntiAlias(true);
mBadgePaint.setStyle(Paint.Style.FILL);
mBadgePaint1 = new Paint();
mBadgePaint1.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.white));
mBadgePaint1.setAntiAlias(true);
mBadgePaint1.setStyle(Paint.Style.FILL);
mTextPaint = new Paint();
mTextPaint.setColor(Color.WHITE);
mTextPaint.setTypeface(Typeface.DEFAULT);
mTextPaint.setTextSize(mTextSize);
mTextPaint.setAntiAlias(true);
mTextPaint.setTextAlign(Paint.Align.CENTER);
}
@Override
public void draw(Canvas canvas) {
if (!mWillDraw) {
return;
}
Rect bounds = getBounds();
float width = bounds.right - bounds.left;
float height = bounds.bottom - bounds.top;
// Position the badge in the top-right quadrant of the icon.
/*Using Math.max rather than Math.min */
float radius = ((Math.max(width, height)/2))/2;
float centerX = (width - radius - 1) + 5;
float centerY = radius - 5;
if (mCount.length() <= 2) {
// Draw badge circle.
canvas.drawCircle(centerX, centerY, (int) (radius + 7.5), mBadgePaint1);
canvas.drawCircle(centerX, centerY, (int) (radius + 5.5), mBadgePaint);
} else {
canvas.drawCircle(centerX, centerY, (int) (radius + 8.5), mBadgePaint1);
canvas.drawCircle(centerX, centerY, (int) (radius + 6.5), mBadgePaint);
// canvas.drawRoundRect(radius, radius, radius, radius, 10, 10, mBadgePaint);
}
// Draw badge count text inside the circle.
mTextPaint.getTextBounds(mCount, 0, mCount.length(), mTxtRect);
float textHeight = mTxtRect.bottom - mTxtRect.top;
float textY = centerY + (textHeight/2f);
if (mCount.length() > 2)
canvas.drawText("99+", centerX, textY, mTextPaint);
else
canvas.drawText(mCount, centerX, textY, mTextPaint);
}
/*
Sets the count (i.e notifications) to display.
*/
public void setCount(String count) {
mCount = count;
// Only draw a badge if there are notifications.
mWillDraw = !count.equalsIgnoreCase("0");
invalidateSelf();
}
@Override
public void setAlpha(int alpha) {
// do nothing
}
@Override
public void setColorFilter(ColorFilter cf) {
// do nothing
}
@Override
public int getOpacity() {
return PixelFormat.UNKNOWN;
}
}
そして追加のコード { BadgeDrawableバッジです。
// Reuse drawable if possible
Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
if (reuse != null && reuse instanceof BadgeDrawable) {
badge = (BadgeDrawable) reuse;
} else {
badge = new BadgeDrawable(mContext);
}
badge.setCount(count);
icon.mutate();
icon.setDrawableByLayerId(R.id.ic_badge, badge);
}
あなたは、任意のビュー
0
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:text="Button" />
<FrameLayout
android:id="@+id/badgecountlayout"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="left"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/badgecount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/round_notification"
android:gravity="center"
android:text="99" />
</FrameLayout>
</FrameLayout>
round_notification.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient android:startColor="@color/yellow_dark" android:endColor="@color/yellow_dark"
android:angle="270"/>
</shape>
関連する問題
- 1. プルダウンメニュー内のアンドロイド通知にバッジを追加するにはどうすればよいですか?
- 2. アプリからバッジ通知を削除するにはどうすればいいですか?
- 3. 目的のCで通知バッジ番号をリセットするにはどうすればよいですか?
- 4. アプリアイコンに番号なしの通知バッジを付けるにはどうすればよいですか?
- 5. Airbrake通知にユーザー情報を追加するにはどうすればよいですか?
- 6. プッシュ通知にカラー画像を追加するにはどうすればよいですか?
- 7. 通知ボタンに操作を追加するにはどうすればよいですか?ここ
- 8. 通知を自動的に追加するにはどうすればよいですか?
- 9. メール通知laravelに条件を追加するにはどうすればよいですか?
- 10. APN、GCM(FCM):リッチメディアを通知に追加するにはどうすればよいですか?
- 11. CodenameOneのタブにバッジを追加するにはどうすればよいですか?
- 12. アプリにドラッグアップメニューを追加するにはどうすればいいですか?
- 13. アプリがアクティブでないときに通知を処理するにはどうすればよいですか?
- 14. Material-UI/React:AppBarにバッジの通知ボタンを正しく追加するにはどうすればいいですか?
- 15. アンドロイドのステータスバー通知にハイパーリンクを追加するにはどうすればいいですか
- 16. Travisに電子メール通知を追加するにはどうすればいいですか?
- 17. 希望のviewControllerに通知する通知を受け取るにはどうすればよいですか?
- 18. アプリ起動後アプリ起動時にバッジ数をリセットするにはどうすればいいですか?
- 19. ローカル通知を使用してアプリをスリープ状態にするにはどうすればよいですか?
- 20. プッシュサービスなしでphonegapアプリから通知を開始するにはどうすればよいですか?
- 21. Uber APIを通じてデジタルウォレットに通貨を追加するにはどうすればよいですか?
- 22. クリックしてアプリを終了する通知を作成するにはどうすればよいですか?
- 23. アプリの開始時にのみ通知を作成するにはどうすればよいですか?
- 24. iOSアプリに通知の詳細を保存するにはどうすればよいですか?
- 25. 設定 - >通知の下に通知を設定するにはどうすればよいですか?
- 26. App Storeのアプリ内購入でサーバに通知するにはどうすればよいですか?
- 27. UIBarButtonItemでバッジを取得するにはどうすればよいですか?
- 28. 通知を設定するにはどうすればよいですか?
- 29. 通知テキストを変更するにはどうすればよいですか?
- 30. iOSプッシュ通知をテストするにはどうすればよいですか?
にDrwabaleを設定することができますが、それはアプリケーションで可能ですか?つまり、アプリケーションのアイコンではなく、アプリケーションのボタンです。 – kinyas