【问题标题】:How to open Activity as a dialog with ActionBar如何使用 ActionBar 将 Activity 作为对话框打开
【发布时间】:2014-11-05 11:42:22
【问题描述】:

我想以对话框的形式打开活动

public class MoveActivity extends Activity {
    private ListView list;
    private DocAdapter adapter;
    private ArrayList<Dictionary<String, String>> mlist;
    DatabaseHelper helper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_move);
        list = (ListView) findViewById(R.id.list);
        helper = ApplicationClass.getDatabaseHelperInstance();
        helper.open(DatabaseHelper.readMode);
        mlist = helper.getDocList();
        helper.close();
        adapter = new DocAdapter(this, mlist);
        list.setAdapter(adapter);
    }

}

【问题讨论】:

  • 为活动&lt;activity android:theme="@android:style/Theme.Dialog" /&gt;设置对话框主题
  • 嘿,你终于搞定了吗?如果你能分享一些代码会有所帮助

标签: android


【解决方案1】:

将活动作为我在AndroidManifest.xml中定义的对话框开始

<activity android:theme="@android:style/Theme.Dialog" />

【讨论】:

    【解决方案2】:

    在清单文件中将活动主题定义为对话框。

    <activity android:theme="@android:style/Theme.Dialog" />
    

    【讨论】:

      【解决方案3】:

      要在 Dialog 中使用操作栏,您必须在 style.xml 中创建一个自定义主题,其父主题为“Theme.AppCompat.Light”。

      <style name="PopupTheme" parent="Theme.AppCompat.Light">
              <item name="android:windowFrame">@null</item>
              <item name="android:windowIsFloating">false</item>
              <item name="android:windowContentOverlay">@null</item>
              <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
              <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
              <item name="android:windowActionModeOverlay">true</item>
              <item name="android:colorBackgroundCacheHint">@null</item>
              <item name="android:windowCloseOnTouchOutside">true</item>
              <item name="android:windowIsTranslucent">true</item>
          </style>
      

      并在您的清单中使用活动标记添加此样式:

      <activity
                  android:name=".MyActivity"
                  android:configChanges="orientation|keyboardHidden|locale"
                  android:screenOrientation="portrait"
                  android:theme="@style/PopupTheme" >
      

      最后在setConytentView(layoutID)之前将此代码添加到您的活动中;

      @Override
          protected void onCreate(Bundle savedInstanceState) {
              // TODO Auto-generated method stub
              super.onCreate(savedInstanceState);
              this.requestWindowFeature(Window.FEATURE_ACTION_BAR);
              this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                  WindowManager.LayoutParams.FLAG_DIM_BEHIND);
              LayoutParams params = this.getWindow().getAttributes(); 
              params.alpha = 1.0f;
              params.dimAmount = 0.5f;
              this.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 
      
              // This sets the window size, while working around the IllegalStateException thrown by ActionBarView
              this.getWindow().setLayout(600,900);
      
              setContentView(R.layout.dialog_move);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-06
        • 1970-01-01
        • 1970-01-01
        • 2010-12-31
        • 1970-01-01
        相关资源
        最近更新 更多