我应该如何创造这个设计的优秀部分?我正在使用 DialogFragment 在弹出窗口中执行此操作,但我无法实现顶部透明的效果。
按钮设计不过background_circle:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#fff"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
使用以下 XML 文件 my_dialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:padding="10dp"
android:orientation="vertical"
android:background="#fff"
android:gravity="center">
<TextView
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text long text"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/background_circle"
android:padding="3dp"
android:src="@drawable/ic_empty_star"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
结果:
星形必须位于布局之外的上部部分。
我试图从我的 .ROOM 数据库中观察所有练习名称的列表AlertDialog。
但是我收到以下错误消息:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Application android.app.Activity.getApplication()' on a null object reference
错误消息出现在这里:
childExerciseViewModel = ViewModelProviders.of((FragmentActivity) context).get(ChildExerciseViewModel.class);
Run Code Online (Sandbox Code Playgroud)
我怎样才能避免这个错误?
添加练习对话框
public class AddExerciseDialog extends AppCompatDialogFragment {
private EditText editTextExerciseName;
private ChildExerciseViewModel childExerciseViewModel;
String userEnteredExerciseName;
int exerciseTypeID;
Button cancelBtn;
Button addBtn;
Context context;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
childExerciseViewModel = ViewModelProviders.of((FragmentActivity) context).get(ChildExerciseViewModel.class);
//return view;
return inflater.inflate(R.layout.layout_dialog_add_exercise, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable …Run Code Online (Sandbox Code Playgroud) java android android-alertdialog android-livedata android-viewmodel
上图显示了一个编辑文本,其文本限制显示在右下角,长度为 250 个字符。当用户在 editText 中键入字符时,“250”会减少。
我一直在尝试将其实现到我的编辑文本中,但这有点具有挑战性。我尝试过各种东西。只是为了让您知道我正在使用alertDialog,其中包含editText。然后,alertDialog 显示一个 xml,其中包含 editText 属性。
谢谢您的帮助!!!!
我需要在我的应用程序中添加一个警报系统.当读取一些数据时,我需要提醒用户数据.我需要一个对话框弹出让用户知道它发生的时间并告诉他们其他一些东西.用户需要单击确定即可.只是为了引起他们的注意.我需要它来制造噪音和振动.我正在调查通知和alertdialogs.AlertDialog似乎是我想要的,但是,我在alertdialog的文档中没有看到任何关于声音和振动的信息.alertdialog有噪音和振动吗?还是有另一种方式让我用声音和振动做到这一点?我需要窗口保持活动状态,直到用户按下确定.
谢谢!
我从网站获取数据并放置在文本视图中,以便我可以使用setGravity(Gravity.CENTER)将其居中.但是,当我将文本视图放在警告对话框中时,我无法再向下滚动以查看消息的结尾.有人可以帮我解决这个问题吗?谢谢
TextView msg1=new TextView(Welcome.this);
//Takes data from a website
msg1.setText(Html.fromHtml(getText("http://www.cellphonesolutions.net/welcome-en")));
msg1.setGravity(Gravity.CENTER);
LinearLayout dialogLayout = new LinearLayout(Welcome.this);
dialogLayout.addView(msg1);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog welcome = new AlertDialog.Builder(Welcome.this).create();
welcome.setView(dialogLayout);
welcome.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//rest of the code....
Run Code Online (Sandbox Code Playgroud) AlertDialog.Builder load_alert = new AlertDialog.Builder(this);
File list = new File("data/data/project/databases/");
if(!list.exists() || !list.isDirectory()){
return;
}
String [] fileList = list.list();
load_alert.setMessage("Please select");
load_alert.setItems(fileList, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast toast = Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_LONG);
toast.show();
}
});
load_alert.show();
Run Code Online (Sandbox Code Playgroud)
这应该将我的数据库文件夹的内容显示为alertdialog.我检查了fileList数组,并且正在填充它.由于某种原因,它不是通过setItems显示.有任何想法吗?
我有一个活动(ImportActivity),其中用户输入一些度量的值并将它们保存到sqlite数据库中.
当用户在导入到数据库后单击"保存"按钮时,我有一个警告对话框(SAVEORBACK_DIALOG_ID),用户可以在此处离开此活动或导入另一个度量.它工作正常.
我的问题是当我尝试在(SAVEORBACK_DIALOG_ID)警告对话之前显示另一个警报对话框(SMS_DIALOG_ID).这是因为我想要求用户发送或不发送短信.
当我运行它时它只显示第二个警告对话框(SAVEORBACK_DIALOG_ID)!

我在活动中:
static final int DATE_DIALOG_ID = 0;
static final int TIME_DIALOG_ID = 1;
static final int SAVEORBACK_DIALOG_ID = 2;
static final int SMS_DIALOG_ID = 3;
Run Code Online (Sandbox Code Playgroud)
我从我的活动中打电话给他们:
// sms dialog(send sms to doctor?yes/no)
showDialog(SMS_DIALOG_ID);
// save or back dialog
showDialog(SAVEORBACK_DIALOG_ID);
Run Code Online (Sandbox Code Playgroud)
这是onCreateDialog方法,我有我的对话框(我删除了一些更容易阅读):
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
case TIME_DIALOG_ID:
return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute,
false);
case SAVEORBACK_DIALOG_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(this); …Run Code Online (Sandbox Code Playgroud) 我一直在使用AppMsg,这是一个以非侵入方式显示警报的第三方库(最初由Cyril Motier构思).图书馆正常运作,但是有没有人知道如何使用图书馆Fragments?
https://github.com/johnkil/Android-AppMsg
可以看出,主要功能makeText需要一个活动context.我如何传递Fragment给这个方法?
public static AppMsg makeText(Activity context, int resId, Style style)
{
return makeText(context, context.getResources().getText(resId), style);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,托里.
我写了一个自定义对话框,它工作得很好.
public class GalleryAlertDialog extends Dialog {}
Run Code Online (Sandbox Code Playgroud)
在课堂上,我用班级来称呼班级
dialog.show();
Run Code Online (Sandbox Code Playgroud)
我希望实现这个目标:

我需要对话框上的按钮,就像这样.
但是,这就是我得到的:

这是布局xml的部分,我在其中声明布局和其中的按钮:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_buttonContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dip"
android:gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_button_popupclose"
android:contentDescription="TODO"
android:tag="btn_close" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_pagerContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ll_buttonContainer"
android:layout_marginTop="80dip"
android:background="@color/white" />
<ToggleButton
android:id="@+id/tbFavorite"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_gravity="bottom|right"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dip"
android:background="@drawable/selector_check"
android:checked="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textOff=""
android:textOn="" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ff212121"
android:gravity="center_vertical"
android:orientation="horizontal" > …Run Code Online (Sandbox Code Playgroud) android transparent android-layout android-alertdialog android-dialog
如何检查我的警报是否已经在屏幕上显示?
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.show();
Run Code Online (Sandbox Code Playgroud)
我可以通过在我的代码中添加一个标志来设置和重置来维护状态,但是如果已经有一个我可以重用的方法呢?