Popup on first launch of Android application

I am trying to find a code that will pop up the first time I run it in an installed application. Very similar to the change log, which is starting to appear in more and more applications. I found several similar codes, but as a beginner, I was not able to figure out exactly where to insert the code, and I always have many errors that still do not work when I try to fix them. I work in Eclipse with an android project, and I use web browsing to show a website.

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">



<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarAlwaysDrawVerticalTrack="false"/>

</LinearLayout>

Java file:

package com.A2Ddesigners.WhatThe;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.KeyEvent;


public class Whatthe extends Activity {
    WebView webview;
    /** Called when the activity is first created. */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
            webview.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new HelloWebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setInitialScale(50); 
        webview.getSettings().setUseWideViewPort(true); 
        webview.loadUrl("http://mdsitest2.com/");
    }
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;


            }

            }   
        }
+3
source share
4 answers

Using my this code, you can display a popup on any type of view in the main activity time.

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class PopupDispaly extends Activity {
    private PopupWindow outComePopup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tiwter_login);
        final View anyView = findViewById(R.id.popo_up); // define heade your view
        anyView.postDelayed(new Runnable() {
            @Override
            public void run() {
                callFirstToolTip(anyView);
            }
        }, 5000); // hear you can put your delay time like 5000 mls

    }
    public void callFirstToolTip(View view) {
        Log.i("Started Info","popup");
        View layout = LayoutInflater.from(PopupDispaly.this).inflate(R.layout.popup_copy_delete, null); // define hear your layout file id.
        LinearLayout layCopyDelete = (LinearLayout) layout.findViewById(R.id.layCopyDelete);// hear define your id of sub lay like LinearLayout.
        outComePopup = new PopupWindow(layout);
        outComePopup.setFocusable(true);
        layCopyDelete.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        outComePopup.setWidth(layCopyDelete.getMeasuredWidth());
        outComePopup.setHeight(layCopyDelete.getMeasuredHeight());
        outComePopup.setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));
        outComePopup.setOutsideTouchable(true);
        outComePopup.showAsDropDown(view);
    }

}

Custome View

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/got_it_bg"
    android:layout_gravity="center_horizontal"
   android:id="@+id/layCopyDelete"
    android:layout_marginLeft="100dp"
    android:orientation="horizontal">

</LinearLayout>
+1

, . http://developer.android.com/guide/topics/ui/dialogs.html

. , onCreateDialog (int) onCreate().

0

PopupWindow.showAsDropDown() , show popupWindow onCreate() 0,5 .

0

PopupWindow.showAtLocation, post . findViewById(android.R.id.content). :

View anyView = findViewById(R.id.anyView);
anyView.post(new Runnable()
{
    @Override
    public void run()
    {
        // Create and show PopupWindow
    }
});
0

All Articles