我的问题类似于这个2岁的问题,我只是发布相同的问题来获得更新的答案,因为很多事情在两年内发生了变化.
我正在开发一个GingerBread +设备的应用程序,我有很多活动,在后台我收到服务器的一些数据.现在基于该数据在某些情况下我需要向Dialog用户显示一个.问题是我如何知道当前最活跃的活动?
我试过,
我曾试图给getApplicationContext()而Dialog创作,但是不工作.抛出一些例外.
一个办法 ?(我真的讨厌它),
一个解决方案可能是通过在Application类中使用变量并在onResume()每个活动上设置它来跟踪当前可见的活动.如果他们有更明智的方法来实现这一点,我真的不想做这本书,我相信他们是更明智的方法来实现这一目标,
我的简单问题是,
如何在当前可见活动上显示对话框?,所以我可以提供对AlertDialog.Builder的引用,我认为这将完成我的工作.如果不是我怎么能在最顶层的Activity上显示一个对话框?
编辑,我使用以下代码私有View.OnClickListener创建一个简单的对话框cancelClickListener = new OnClickListener(){
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
LoginActivity.this);
// set title
alertDialogBuilder.setTitle("Roobroo will exit..");
// set dialog message
alertDialogBuilder
.setMessage("Are you sure you want to exit ?")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// …Run Code Online (Sandbox Code Playgroud) 基本上问题在标题中说明.使用一个或另一个的任何偏好?也许某些特定的任务,其中一个是优越的/更有效/更好的另一个?
我希望创建一个看起来像弹出窗口的活动
这是活动的透明背景,我希望在设备屏幕右上角的scree上的自定义位置显示它
我所做的就是onCreate像popty一样流行
Display display = getWindow().getWindowManager().getDefaultDisplay();
WindowManager.LayoutParams params = getWindow().getAttributes();
// params.x = -20;
params.height = (display.getHeight()) / 2;
params.width = (display.getWidth()) / 2;
// params.y = -10;
params.gravity = Gravity.RIGHT;
getWindow().setAttributes(params);
Run Code Online (Sandbox Code Playgroud)
在maifest
<activity android:name=".DialogAct"
android:theme="@android:style/Theme.Holo.Light.NoActionBar"></activity>
Run Code Online (Sandbox Code Playgroud)
这就是我的启动器活动的样子

所以,当我点击动作栏上的搜索时,我正在向我的新活动发送意图.我想让它看起来像搜索图标下面的弹出这我得到的是

您可以看到单击上一个活动的搜索并加载新活动(蓝色部分).如您所见,新活动将移至屏幕中心.但我希望它只是在操作栏图标下方.
我试过了params.gravity = Gravity.TOP | Gravity.RIGHT;.然后我得到了这个

我想把它放在上一个活动的操作栏下面.我尝试了许多方法来实现它但失败了.所以任何人都可以建议一种方法
我正在开发一种反馈类型的应用程序,当我单击"submitnow"按钮时,我收到以下错误
活动已经泄露窗口
com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0
Run Code Online (Sandbox Code Playgroud)
以下是我的代码,请帮帮我.
public class SignOut_Activity extends SherlockActivity implements
OnClickListener {
Button btnSubmitNow, btnSubmitLater;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.signout);
((TextView) findViewById(R.id.tvSubTitle))
.setText(StoresListAdapter.StoreName);
btnSubmitNow = (Button) findViewById(R.id.btnSubmitNow);
btnSubmitLater = (Button) findViewById(R.id.btnSubmitLater);
btnSubmitNow.setOnClickListener(this);
btnSubmitLater.setOnClickListener(this);
progressDialog = new ProgressDialog(SignOut_Activity.this);
progressDialog.setMessage("Uploading data, please wait...");
}
@Override
public boolean onOptionsItemSelected(
com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; finish activity to go home
finish();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
} …Run Code Online (Sandbox Code Playgroud) 我试图在3秒后自动关闭ProgressDialog框.这是对话框:
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Connecting");
progress.setMessage("Please wait while we connect to devices...");
progress.show();
Run Code Online (Sandbox Code Playgroud)
我尝试过几种方法,但我无法让其中任何一种方法起作用.一个简单的时间或任何事情都可以满足.谢谢.
我正在尝试在a中的卡片点击中实现自定义行为RecyclerView,我想要完成的是通过在其上面扩展和添加fab来为所选项目布局设置动画,同时使屏幕变暗.我当前的方法是在项目点击时调用notifyItemChanged,当调用bindViewHolder方法时,我正在添加fab,因为项目布局root将animateLayoutChanges属性设置为true,项目正在精细扩展,但我无法管理调暗卡后面的屏幕,就像卡片是对话框一样,我也希望卡片外面的点击可以解除所有的更改,有没有其他方法可以实现这一点?
android android-dialog android-cardview android-recyclerview
我已经实现DataBinding了Activity,Fragment和RecyclerView.现在尝试进行Dialog,但有点混淆如何在其中设置自定义视图?
这是我实现的代码Dialog.
Dialog dialog = new Dialog(context);
dialog.getWindow();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
LayoutTermsBinding termsBinding;
dialog.setContentView(R.layout.layout_terms);
dialog.getWindow().setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
dialog.show();
Run Code Online (Sandbox Code Playgroud)
我知道这是不是Activity我们可以执行DataBindingUtil.setContentView()和Fragment可以执行DataBindingUtil.inflate(),但我混淆如何转换dialog.setContentView(R.layout.layout_terms);用DataBinding.
标题是,我似乎无法调暗我所做的自定义对话框的背景.无数解决方案在线提到了下面第一个代码段中的最后3行代码,这对对话框的UI没有任何影响.
请参阅以下代码:
Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
TextView textView = (TextView) dialog.findViewById(R.id.textView);
textView.setText("Custom Text Example");
dialog.show();
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
layoutParams.dimAmount = .7f;
dialog.getWindow().setAttributes(layoutParams);
Run Code Online (Sandbox Code Playgroud)
自定义对话框的布局xml文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progressDialogCustom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/dialog_black"
android:orientation="horizontal"
android:padding="10dp" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="@android:color/white"
android:text="Updating Profile . . ." />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
该@drawable/dialog_black文件如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/background_dark" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
<stroke
android:width="1px"
android:color="@android:color/darker_gray" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" /> …Run Code Online (Sandbox Code Playgroud) 我的要求就像每当用户从数字选择器中选择任何数字时,该数字应该打印在某个文本视图上,第二次,当用户再次打开对话框时,应该在该对话框上显示先前选择的数字
...
...
view = (TextView) findViewById(R.id.textView7);
LinearLayout L = (LinearLayout) findViewById(R.id.linearLayout5);
L.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showdialog();
}
});
}
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
Log.i("value is",""+newVal);
}
public void showdialog()
{
Dialog dialog = new Dialog(NameActivity.this);
View npView = getLayoutInflater().inflate(R.layout.multidialog, null);
final NumberPicker firPicker =
(NumberPicker) npView.findViewById(R.id.numberPicker1);
firPicker.setMaxValue(9);
firPicker.setMinValue(0);
final NumberPicker secPicker =
(NumberPicker) npView.findViewById(R.id.numberPicker2);
secPicker.setMaxValue(9);
secPicker.setMinValue(0);
final NumberPicker tirPicker =
(NumberPicker) npView.findViewById(R.id.numberPicker3);
tirPicker.setMaxValue(9);
tirPicker.setMinValue(0);
AlertDialog.Builder builder = new …Run Code Online (Sandbox Code Playgroud) 不确定我是否遗漏了一些明显的东西,但是当显示对话框时,我无法在父屏幕中获取灰色叠加背景。使用此代码创建一个全新的应用程序:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
TestsTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Column(modifier = Modifier.fillMaxSize()) {
Greeting("Android")
}
CustomDialog()
}
}
}
}
}
@Composable
fun CustomDialog() {
var showDialog by remember { mutableStateOf(true) }
if (showDialog) {
Dialog(onDismissRequest = {
showDialog = !showDialog
}) {
Column(modifier = Modifier.fillMaxWidth()
.background(color = Color.Red)) {
Text(text = "Hello …Run Code Online (Sandbox Code Playgroud) android ×10
android-dialog ×10
android-ui ×1
android-view ×1
android-xml ×1
data-binding ×1
java ×1
overlay ×1