To solve this issue you need to change android:launchMode="singleTop" in AndroidMenifest.xml file for that activity.
Wednesday, 20 December 2017
Android Webview loaddata not changing content second time
Android Webview's loaddata method have issue.
use following way to load data to webview
use following way to load data to webview
webView.loadDataWithBaseURL(null, htmlContent, null, "utf-8", null);
Thursday, 26 October 2017
Android web view set wrap_content height
Use following code to set android web view set wrap_content height
- webview's parent should have match parent height
- and set webview as wrap_content height
---Layout file ---
---java file code---
Following is IMP part
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="@dimen/twenty" android:src="@drawable/img_sc2_logo" /> <WebView android:id="@+id/wvInfo" android:layout_width="match_parent" android:layout_height="wrap_content"> </WebView> </LinearLayout> </ScrollView>
---java file code---
Following is IMP part
binding.wvInfo.loadUrl(ApiRequestUtil.PAGE_APP_WELCOME); binding.wvInfo.getSettings().setLoadWithOverviewMode(true); binding.wvInfo.getSettings().setUseWideViewPort(true); binding.wvInfo.getSettings().setJavaScriptEnabled(true); binding.wvInfo.getSettings().setBuiltInZoomControls(false); ViewTreeObserver viewTreeObserver = binding.wvInfo.getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { int height = binding.wvInfo.getMeasuredHeight(); if( height != 0 ){ // Toast.makeText(getActivity(), "height:"+height,Toast.LENGTH_SHORT).show(); binding.wvInfo.getViewTreeObserver().removeOnPreDrawListener(this); } return false; } });
Wednesday, 1 March 2017
Android get image from view
To get bitmap from any view use following code.
rootView.setDrawingCacheEnabled(true); rootView.layout(0, 0, rootView.getWidth(), rootView.getHeight()); rootView.buildDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(rootView.getDrawingCache()); rootView.setDrawingCacheEnabled(false);
Wednesday, 18 January 2017
Android popup menu display causes RecyclerView scroll up
If you using android.support.v7.widget.PopupMenu then you may face this issue. Simple solution is to use android.widget.PopupMenu.
But if you need to show icons in your popupMenu then you have to use android.support.v7.widget.PopupMenu. so you should apply following solution.
But if you need to show icons in your popupMenu then you have to use android.support.v7.widget.PopupMenu. so you should apply following solution.
You can have your AnchorView override
requestRectangleOnScreen()
and return false. This will prevent any parent ScrollView or RecyclerView
from scrolling.
So, For ex If I have anchor view as ImageView then code should be like following.
public class MenuImageView extends ImageView { public MenuImageView(Context context) { super(context); } public MenuImageView(Context context, AttributeSet attrs) { super(context, attrs); } public MenuImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public MenuImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } // THIS IS IMP METHOD (RETURN FALSE). ADD IT SO YOUR RECYCLER VIEW WILL NOT SCROLL WHEN YOU CLICK ON MENU. @Override public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { return false; } }
Subscribe to:
Posts
(
Atom
)