How do they do it? Dialogs over home screen

前端 未结 4 2083
时光取名叫无心
时光取名叫无心 2020-12-30 09:19

I\'m writing an Android application and I would like to place a dialog or view over the home screen so that a user can enter text without jumping into my full application. I

相关标签:
4条回答
  • 2020-12-30 09:54

    They are launching an activity, but they've set the activity's theme so it looks like a Dialog.

    In your manifest, you have to add something like this under the <activity> tag: android:theme="@android:style/Theme.Dialog"

    0 讨论(0)
  • 2020-12-30 09:55

    Thanks a lot, I tried with Theme.Dialog

      <activity android:name=".language"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.Dialog">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
    

    But in my code, there is 2 different floating windows : my layout and the tile. Here is the following code:

    import android.app.Activity;
    import android.os.Bundle;
    import android.content.Intent;
    import android.app.Dialog; 
    
    public class language extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
           // setContentView(R.layout.main);
            Dialog dialog = new Dialog(this); 
            dialog.setContentView(R.layout.main); 
            dialog.setTitle("Raygional"); 
            dialog.show();
    
        }
    }
    

    PS : I know this should be a question rather than an answer

    0 讨论(0)
  • 2020-12-30 09:55

    Use Service for that

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.getApplicationContext().startActivity(intent);
    

    below is some code`

    public class HomepopupDataService extends Service {
    
    private static final String TAG = "HomepopupDataService";
    
    @Override
    public void onCreate() {
        Log.i(TAG, "Service onCreate");
    }
    
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub
        Log.i(TAG, "Service onStartCommand");
    
        CountDownTimer dlgCountDown;
        Log.e("---------------", "onHandleIntent");
        dlgCountDown = new CountDownTimer(10000, 1000) {
            public void onTick(long millisUntilFinished) {
                Log.e("---------------", "onHandleIntent++");
            }
    
            public void onFinish() {
                Intent i = new Intent(getApplicationContext(),
                        DialogActivity.class);
    
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getApplicationContext().startActivity(i);
            }
        }.start();
        return super.onStartCommand(intent, flags, startId);
    }
    
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        Log.i(TAG, "Service onBind");
        return null;
    }
    
    @Override
    public void onDestroy() {
        Log.i(TAG, "Service onDestroy");
    }
    
    }
    
    0 讨论(0)
  • 2020-12-30 10:13

    My problem was that the application always launched to display the dialog.

    To solve this, I set the activity lauch mode to singleInstance in the manifest. Now it shows the dialog over the home screen!

    0 讨论(0)
提交回复
热议问题