2017-08-08 5 views
0

の直上に通知カウンタを追加する方法:アンドロイドは - 私はImageViewの右側の同様の通知カウンターでアプリを持ちたいImageViewの

MyPhoto.png

:ここに私のレイアウトの写真です

私は、このような通知のカウンターを持つようにしたい。ここでは

OriginalApp.png

は私activity_menuレイアウトです:

ここでは3210
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="datasite.com.konnex.Menu" 
    android:background="#ffffff"> 

    <android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#3fc0ea"> 

     <ImageButton 
      android:layout_width="120dp" 
      android:layout_height="38dp" 
      android:background="@drawable/lg1" 
      android:layout_marginLeft="130dp" /> 

     <SearchView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="90dp"/> 
    </android.support.v7.widget.Toolbar> 

    <FrameLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <GridLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:columnCount="2"> 
     <ImageView 
      android:layout_width="90dp" 
      android:layout_height="90dp" 
      android:src="@drawable/cases" 
      android:layout_marginLeft="60dp" 
      android:layout_marginTop="40dp" 
      android:id="@+id/img_cases"/> 
      <ImageView 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:src="@drawable/invoices" 
       android:layout_marginLeft="80dp" 
       android:layout_marginTop="40dp" /> 

      <ImageView 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:src="@drawable/announcement" 
       android:layout_marginLeft="60dp" 
       android:layout_marginTop="40dp" /> 
      <ImageView 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:src="@drawable/users" 
       android:layout_marginTop="40dp" 
       android:layout_marginLeft="80dp"/> 
      <ImageView 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:src="@drawable/document" 
       android:layout_marginTop="60dp" 
       android:layout_marginLeft="60dp" /> 
      <ImageView 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:src="@drawable/meetings" 
       android:layout_marginTop="60dp" 
       android:layout_marginLeft="80dp"/> 

     </GridLayout> 
    </FrameLayout> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/navigation" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#fffafa" 
     app:menu="@menu/navigation" 
     app:itemIconTint="@color/dark" 
     app:itemTextColor="@color/dark" /> 

</LinearLayout> 

は私のmenu.javaクラスです:

public class Menu extends AppCompatActivity { 

      private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener 
        = new 

BottomNavigationView.OnNavigationItemSelectedListener() { 

      @Override 
      public boolean onNavigationItemSelected(@NonNull MenuItem item) { 

       switch (item.getItemId()) { 
        case R.id.nav_about: 
         return true; 
        case R.id.nav_location: 
         return true; 
        case R.id.nav_phone: 
         return true; 
        case R.id.nav_home: 
         return true; 
       } 
       return false; 
      } 
     }; 

      @Override 
      protected void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.activity_menu); 

      } 
    } 

この問題の解決策を見つけるために助けてください。私は多くの回答を検索しましたが、私の場合に固有の解決策は見つかりませんでした。前もって感謝します!

+0

あなたはこの[アンドロイド-viewbadger](https://github.com/jgilfelt/android-viewbadger)ライブラリ –

答えて

0

を経由して、それらを更新することができます。

<GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:columnCount="2"> 
     <FrameLayout 
      android:layout_width="90dp" 
      android:layout_height="90dp"> 
      <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:src="@drawable/cases"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="1" 
      android:background="@android:color/red" 
      android:layout_gravity="top|end"/> 
     </FrameLayout> 
</GridLayout> 
+0

Ahsan thanks。感謝する – Zoffa

0
<RelativeLayout 
    android:layout_width="100dp" 
    android:layout_height="100dp"> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="100dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#fc0505" 
     android:text="10" 
     android:layout_alignParentRight="true" 
     android:textSize="18sp"/> 

</RelativeLayout> 
+0

のAvinashを試すことができますか?テキストビューで作業していますが、バッジを設定することはできません( – Zoffa

0

RelativeLayoutGridLayout内のあなたのイメージをラップし、RelativeLayout内部notificaton指標を置きます。 例:

<RelativeLayout 
    android:layout_width="90dp" 
    android:layout_height="90dp"> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/cases" 
    android:layout_marginLeft="60dp" 
    android:layout_marginTop="40dp" 
    android:id="@+id/img_cases"/> 
<TextView 
    android:id="@+id/item1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#FFFFFF" 
    android:background="#FF0000"/> 
</RelativeLayout> 

、あなたがこのようでframeLayoutであなたのあらゆるImageViewのラップ

GridLayout gridLayout.... 
TextView item1 = (TextView) gridLayout.findViewById(R.id.item1); 
item1.setText("3"); // 3 notifications 
+0

テキストビューのおかげで助かりましたが、アイコンの上にバッジカウンターを作成する方法は? – Zoffa

関連する問題