如何打开活动与动作条的对话动作

由网友(Memory.荒年〆)分享简介:我想打开活动的对话框公共类MoveActivity延伸活动{私人的ListView列表;私人DocAdapter适配器;私人的ArrayList<字典<字符串,字符串>> mlist;DatabaseHelper帮手;@覆盖保护无效的onCreate(包savedInstanceState){/...

我想打开活动的对话框

 公共类MoveActivity延伸活动{
    私人的ListView列表;
    私人DocAdapter适配器;
    私人的ArrayList<字典<字符串,字符串>> mlist;
    DatabaseHelper帮手;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        // TODO自动生成方法存根
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_move);
        名单=(ListView控件)findViewById(R.id.list);
        辅助= ApplicationClass.getDatabaseHelperInstance();
        helper.open(DatabaseHelper.readMode);
        mlist = helper.getDocList();
        helper.close();
        适配器=新DocAdapter(这一点,mlist);
        list.setAdapter(适配器);
    }

}
 

解决方案

有关对话框中使用行动起来吧,你必须在你的style.xml与父母为Theme.AppCompat.Light创建自定义主题。

 <样式名称=PopupTheme父=Theme.AppCompat.Light>
        <项目名称=机器人:窗框> @空< /项目>
        <项目名称=机器人:windowIsFloating>假< /项目>
        <项目名称=机器人:windowContentOverlay> @空< /项目>
        <项目名称=机器人:windowAnimationStyle> @android:款式/ Animation.Dialog< /项目>
        <项目名称=机器人:windowSoftInputMode> stateAlwaysHidden< /项目>
        <项目名称=机器人:windowActionModeOverlay>真< /项目>
        <项目名称=机器人:colorBackgroundCacheHint> @空< /项目>
        <项目名称=机器人:windowCloseOnTouchOutside>真< /项目>
        <项目名称=机器人:windowIsTranslucent>真< /项目>
    < /风格>
 
两小段人物对话 不可以是你说 我说 大家说

而在你的清单中添加此风格的活动标签:

 <活动
            机器人:MyActivityNAME =
            机器人:configChanges =定位| keyboardHidden |语言环境
            机器人:screenOrientation =画像
            机器人:主题=@风格/ PopupTheme>
 

和前 setConytentView(layoutID)最后添加此code。在您的活动;

  @覆盖
    保护无效的onCreate(包savedInstanceState){
        // TODO自动生成方法存根
        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);

        //该设置窗口的大小,同时抛向四周ActionBarView的IllegalStateException异常工作
        this.getWindow()的setLayout(600900)。

        的setContentView(R.layout.dialog_move);
}
 

I want to open activity as dialog

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);
    }

}

解决方案

For using action bar in Dialog, you have to create a custom theme in your style.xml with parent as "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>

And add this style in your manifest with activity tag:

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

and last add this code in your activity before 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);
}

阅读全文

相关推荐

最新文章