Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:35:16+00:00 2026-06-16T04:35:16+00:00

My app has a webview and some buttons inside a LinerLayout. the problem is,

  • 0

My app has a webview and some buttons inside a LinerLayout.

the problem is, I want the buttons to be on bottom in portrait mode and on left in landscape mode while the webview maintains it’s state.

Two different layout doesn’t work as it force recreation of the activity that refresh the webview. for now I use android:configChanges=”orientation” in activity tag so webview doesn’t get refreshed on orientation change.

Is there anyway to replace the layout of buttons on the change of screen mode?

enter image description here

portrait mode

enter image description here

landscape mode

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:35:19+00:00Added an answer on June 16, 2026 at 4:35 am

    I tested fragments, but dealing with fragment makes things much more complex and the fragment itself needs saving and restoring which may not work in a webview which has javascript state, So I searched more and find a nice article somewhere and with some modification I came to a solution which I suggest:

    First, add android:configChanges="orientation|screenSize|keyboard|keyboardHidden" so the app handles the config changes instead of android.

    Make two different layout for landscape and portrait. In both layouts instead of webview place a FrameLayout which acts as a placeholder for the webview.

    Define initUI method like this and put everything related to UI initialization in this method:

    public void initui()
    {
        setContentView(R.layout.main);
        if (wv == null) wv = new WebView(this);
        ((LinearLayout)findViewById(R.id.webviewPlace)).addView(wv);
        findViewById(R.id.home).setOnClickListener(this);
    }
    

    If the webview doesn’t exist yet it will be created and after setContentView(R.layout.main) it will be added to the layout. Any other UI customization you need came after this.

    and in onConfigurationChanged:

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        ((LinearLayout)findViewById(R.id.webviewPlace)).removeAllViews();
        super.onConfigurationChanged(newConfig);
        initUI();
    }
    

    In onConfigChange the webview is removed from old placeholder and initui will be called which will add it back to the new layout.

    In oncreate() call initui() so the ui will be initialized for the first time.

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        initUI()
    }
    

    I wish it would be helpful for someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app has to support landscape/portrait mode only for tablets, phones will only support
My iPhone app has some tabs and main one is showing a webView object
In my Android app I create an AlertDialog that has a WebView inside. The
I am designing an app which has a number of native widgets and some
I have a Android WebView app and it has YouTube videos embedded in it.
I am building an android app which has a webview. The webview will display
1) I load a URL in UIWebview ,which has some images .I want to
i am using a webview in an app which has keep me signed in
My android app has a webview. Where i load a webpage to give user
My Android app has a main WebView (HTML loaded from a local resource) which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.