简体   繁体   中英

Could you give me a short Android code to create this?

http://habrastorage.org/storage/211878a0/14f474e6/bc73d2e8/a709e893.gif

how can I utilize the Toast object to ask a question?

I searched around but was not able to find how to make a Toast object ask a question

Thanks a lot Stack Overflow

here is a sample: the solution is using an alert dialog with a layout that has a label and a text box.

public Dialog create()
{
    LayoutInflater li = LayoutInflater.from(this._context);
    this._view = li.inflate(R.layout.prompt_dialog, null);

    AlertDialog ad = new AlertDialog.Builder(this._context).create();

    ad.setView(this._view);

    if(this._title != null)
    {
        ad.setTitle(this._title);
    }

    if(this._icon != 0)
    {
        ad.setIcon(this._icon);
    }

    TextView tv1 = (TextView)this._view.findViewById(R.id.prompt_dialog_message);
    tv1.setText(this._message);

    ad.setButton(DialogInterface.BUTTON_POSITIVE, _context.getString(R.string.ok), this);
    ad.setButton(DialogInterface.BUTTON_NEUTRAL, _context.getString(R.string.cancel), this);

    return ad;
}

I've used these in my Emergency Tools App And I didn't had any problems :)

Actually that's just a PreferenceActivity. Take a look at the JavaDoc for http://developer.android.com/reference/android/preference/PreferenceActivity.html

What you see is not a Toast notification.

It is a CustomDialog read more here

This is an EditTextPreference inside a PreferenceActivity

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mypref="http://schemas.android.com/apk/res/com.tneele.daynightlwp"
    android:title="@string/settings_title"
    android:key="daynightwallpaper_settings">
    <EditTextPreference
        android:dialogTitle="UserName" />
</PreferenceScreen>

PreferenceActivity:

public class MyPreferenceActivity extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preferences);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM