Custom view in menuItem
Last active
November 27, 2018 05:23
-
-
Save Kolyall/feb357db2afdd1b21198ffad4cfa6fd8 to your computer and use it in GitHub Desktop.
Custom view in menuItem
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center" | |
android:orientation="vertical" | |
tools:background="@color/white"> | |
<ImageView | |
android:id="@+id/cartImage" | |
android:padding="10dp" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:src="@drawable/ic_catalog" /> | |
<com.octanner.android.performance.view.CartCountView | |
android:id="@+id/cart_count_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignEnd="@+id/cartImage" | |
android:layout_alignTop="@+id/cartImage" | |
android:gravity="center" | |
android:padding="1dp" | |
android:layout_margin="10dp" | |
android:textColor="@color/white" | |
android:textSize="@dimen/cart_menu_value_text_size" | |
android:visibility="gone" | |
tools:text="1" | |
tools:visibility="visible" /> | |
</RelativeLayout> |
This file contains 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
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
super.onCreateView(inflater, container, savedInstanceState); | |
setHasOptionsMenu(true); | |
} | |
MenuItem menuItemCart; | |
@Override | |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | |
if (menuItemCart == null) { | |
inflater.inflate(R.menu.menu_catalog_body, menu); | |
menuItemCart = menu.findItem(R.id.menu_item_cart); | |
View cartView = menuItemCart.getActionView(); | |
mCartImage = (ImageView) cartView.findViewById(R.id.cartImage); | |
mCartCountView = (CartCountView) cartView.findViewById(R.id.cart_count_view); | |
cartView.setOnClickListener(v -> { | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment