Log.v(“ThreeTips”, “#4”)

Mert SIMSEK
2 min readOct 21, 2016

--

1- Changing menu item’s text and icon

Changed icon color and text color

If you want to change text color of single item, you can do by using SpannebleString.

MenuItem menuItem = navigationView.getMenu().getItem(0);
SpannableString s = new SpannableString(menuItem.getTitle().toString());
s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)), 0, s.length(), 0);
menuItem.setTitle(s);

You can also add icon property to your menu.xml

<item
android:id="@+id/nav_login_signup"
android:icon="@drawable/ic_account_circle_green_24dp"
android:title="@string/menu_login_signup" />

But icon will not show the right color. You should set item tint list null. Otherwise it wont work.

navigationView.setItemIconTintList(null);

2- Using <include> tag in DataBinding

You can use <include> tag in databinding. With this, you can pass your object to included layout.

As you see both “viewModel” names are same. And they should. We are calling “bind:viewModel=”@{viewModel}” to bind out viewModel object to included layout.

You can set both textview1 and textview2 like;

MainBinding binding = MainBinding.inflate(getLayoutInflater());
binding.textview1.setText(“Hello”);
binding.included.textview2.setText(“First World”);

You should give an id to your include layout so you can go like binding.included.{id in your included layout}.

4- Using PopUpWindow in Android

PopupWindow mPopupWindow=new PopupWindow(context);
mPopupWindow.setContentView(contentView);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
mPopupWindow.setElevation(10);
mPopupWindow.setOutsideTouchable(outsideTouch);
mPopupWindow.setAnimationStyle(animationStyle);
mPopupWindow.setOnDismissListener(dismissListener);
mPopupWindow.setWidth(width);
mPopupWindow.setHeight(height);

setContentView : You can give any view as parameter. I created recycelerview and recyclerview Adapter and gave it as contentView.

setBackgroundDrawable : Takes Drawable as parameter. You can also give .png like ContextCompat.getDrawable(context, R.id.background.png)

setElevation : specifies the elevation(shadow).

setAnimationStyle: I think it is the most useful method. You can animate in and animate out you popupwindow. First, you should create your animation xmls.

dialog_in.xml<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:fillAfter="true"
android:duration="300"
android:pivotX = "0%"
android:pivotY = "0%"
/>

<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="300" />

</set>
dialog_out.xml<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:fillAfter="true"
android:duration="300"
android:pivotX = "0%"
android:pivotY = "0%"
/>

<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="300" />

</set>

Then you need to create animation as style.(res/values/styles.xml)

<style name="dialogAnimation">
<item name="android:windowEnterAnimation">@anim/dialog_in</item>
<item name="android:windowExitAnimation">@anim/dialog_out</item>
</style>

then you can give style as parameter.

mPopupWindow.setAnimationStyle(R.style.dialogAnimation);

Thanks for reading. If you have any question, please don’t hesitate. If you realize points that I’m wrong, please correct me.

--

--

Mert SIMSEK
Mert SIMSEK

Responses (1)