Android中activity以dialog的形式出现
来源:互联网 发布:一维数组的定义方式 编辑:程序博客网 时间:2024/05/17 00:07
activity变身为dialog可以实现多功能的dialog,闲话少说直接上代码!
MainActivity.class
/** * Activity伪装成的Dialog需要继承Activity * 弹窗Activity需要添加主题Theme */public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void start(View view) { startActivity(new Intent(MainActivity.this, DialogActivity.class)); }}
activity_mian.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="jpceshi.jiaxiao.com.dialogactivity.MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="start" android:text="跳转" /></LinearLayout>
跳转后出现的dialog样式
DialogActivity .class
/**在edittext中输入内容后点击button会将内容直接显示到textView中。*/public class DialogActivity extends Activity { private EditText mEditText; private Button mButton; private TextView mTextView; private String str; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); initView(); } private void initView() { mEditText = (EditText) findViewById(R.id.edtext); mTextView = (TextView) findViewById(R.id.tvshow); mEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { str = s.toString(); } }); } public void addText(View view) { if (str != null) { mTextView.setText(str); } else { mTextView.setText("null"); } }}
activity_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="200dp" android:layout_height="200dp" android:orientation="vertical" tools:context="jpceshi.jiaxiao.com.dialogactivity.activity.DialogActivity"> <EditText android:id="@+id/edtext" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:gravity="center" android:hint="请输入" android:textColor="@android:color/black" android:textColorHint="@android:color/holo_blue_light" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:drawable/button_onoff_indicator_on" android:onClick="addText" android:text="添加" /> <TextView android:id="@+id/tvshow" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textColor="@android:color/black" /></LinearLayout>
注:
最重要的一步是:在AndroidManifest.xml文件中给需要显示成dialog样式的
Activity添加 android:theme=”@android:style/Theme.Dialog”(系统自带 的样式,也可以自定义样式)
阅读全文
0 0
- Android中activity以dialog的形式出现
- Android如何将Activity以Dialog的形式显示
- Android如何将Activity以Dialog的形式显示
- Android如何将Activity以Dialog的形式显示
- android activity以dialog形式展现,强大的原生!
- Android如何将Activity以Dialog的形式显示
- android中的activity以弹出窗的形式出现
- Activity 以 Dialog 形式存在
- activity以Dialog形式存在
- 以Dialog形式显示Activity
- activity以Dialog形式存在
- Activity 以 Dialog 形式存在
- Activity 以 Dialog 形式存在
- activity以Dialog形式显示
- Activity以dialog形式打开
- Activity 以 Dialog 形式存在
- 将Android Activity以对话框Dialog形式显示
- 将Android Activity以对话框Dialog形式显示
- bad interpreter: No such file or directory 解决方法
- 各种梯度优化算法介绍(SGD Loss剧烈波动)
- BGP专线 解决南北互联互通
- 消息队列原理
- #pragma 处理警告
- Android中activity以dialog的形式出现
- 模块化
- 心灵鸡汤部分
- PCRE、PCRE2 以及PCRE++ 使用教程
- 35 个 Java 代码性能优化总结
- Newtonsoft.Json DataSet/DataTable转化为JSON字符串
- Centos 6.9 关闭http,Nginx版本信息
- 数据结构和算法的关系
- 关于v-model的使用,(vue)