<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_expanded="true" android:drawable="@drawable/arrow_up" />
<item android:drawable="@drawable/arrow_down" />
</selector>
The images have to be 9 patch images, like the following:Align icon to the right
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
listView.setIndicatorBounds(width-getPixelFromDips(HORIZONTAL_PADDING*2)-getPixelFromDips(35), width-getPixelFromDips(HORIZONTAL_PADDING*2-getPixelFromDips(5)));
} else {
listView.setIndicatorBoundsRelative(width-getPixelFromDips(HORIZONTAL_PADDING*2)-getPixelFromDips(35), width-getPixelFromDips(HORIZONTAL_PADDING*2)-getPixelFromDips(5));
}
}
public int getPixelFromDips(float pixels) {
final float scale = getResources().getDisplayMetrics().density;
return (int) (pixels * scale + 0.5f);
}
Note: If you get a "No resource found..." even when the 9 patch is there it is because the 9 patch is not properly created.


No hay comentarios:
Publicar un comentario