Posts

Showing posts with the label Android 5.0 Lollipop

CardView Not Showing Shadow In Android L

Image
Answer : After going through the docs again, I finally found the solution. Just add card_view:cardUseCompatPadding="true" to your CardView and shadows will appear on Lollipop devices. What happens is, the content area in a CardView take different sizes on pre-lollipop and lollipop devices. So in lollipop devices the shadow is actually covered by the card so its not visible. By adding this attribute the content area remains the same across all devices and the shadow becomes visible. My xml code is like : <android.support.v7.widget.CardView android:id="@+id/media_card_view" android:layout_width="match_parent" android:layout_height="130dp" card_view:cardBackgroundColor="@android:color/white" card_view:cardElevation="2dp" card_view:cardUseCompatPadding="true" > ... </android.support.v7.widget.CardView> Do not forget that to draw shadow you must use hardwareAccelerate...

Android Material Design Inline Datepicker Issue

Answer : The calendarViewShown attribute is deprecated in the calendar-style date picker. If you want the spinner-style date picker back, you can set the datePickerMode attribute to spinner . <DatePicker ... android:datePickerMode="spinner" /> As for the scrolling issue, the calendar-style date picker doesn't support nested scrolling.

Android : Control Smooth Scroll Over Recycler View

Answer : It's unclear what you mean when you say " smoothScroll ". You could be referring to the automatic " smoothScrollToPosition " which will automatically scroll to a specified position, you could be talking about manual scrolling and you could be talking about flinging. For the sake of prosperity, I will attempt to answer all of these issues now. 1. Automatic smooth scrolling. Inside your layout manager, you need to implement the smoothScrollToPosition method: @Override public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) { // A good idea would be to create this instance in some initialization method, and just set the target position in this method. LinearSmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) { @Override public PointF computeScrollVectorForPosition(int targetPosition) { int yDelta = calculateC...

Android Lollipop Set Status Bar Text Color

Answer : You can not set the status bar text color by specifying any color explicitly But you can try below alternative which is Added in API 23, You can use "android:windowLightStatusBar" attribute in two ways "android:windowLightStatusBar" = true, status bar text color will be compatible (grey) when status bar color is light "android:windowLightStatusBar" = false, status bar text color will be compatible (white) when status bar color is dark <style name="statusBarStyle" parent="@android:style/Theme.DeviceDefault.Light"> <item name="android:statusBarColor">@color/status_bar_color</item> <item name="android:windowLightStatusBar">false</item> </style> You can check above api in below link - https://developer.android.com/reference/android/R.attr.html#windowLightStatusBar Here's a Java implementation of Gandalf458's answer. /** Changes the ...

Android Support Design TabLayout: Gravity Center And Mode Scrollable

Answer : Tab gravity only effects MODE_FIXED . One possible solution is to set your layout_width to wrap_content and layout_gravity to center_horizontal : <android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" app:tabMode="scrollable" /> If the tabs are smaller than the screen width, the TabLayout itself will also be smaller and it will be centered because of the gravity. If the tabs are bigger than the screen width, the TabLayout will match the screen width and scrolling will activate. this is how i did it TabLayout.xml <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background=...