當前位置: 首頁>>代碼示例>>Java>>正文


Java Toast.setGravity方法代碼示例

本文整理匯總了Java中android.widget.Toast.setGravity方法的典型用法代碼示例。如果您正苦於以下問題:Java Toast.setGravity方法的具體用法?Java Toast.setGravity怎麽用?Java Toast.setGravity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.Toast的用法示例。


在下文中一共展示了Toast.setGravity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startSearchOptimalThreshold

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Update widgets and send an event "START_SEARCH_THRESHOLD" to {@link Main2Activity}
 */
private void startSearchOptimalThreshold() {
    progressBarSearchOptimalThreshold.setVisibility(View.VISIBLE);
    searchOptimalThresholdButton.setText(getString(R.string.button_threshold_text_stop));
    searchOptimalThresholdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            stopSearchOptimalThreshold(); // behavior of searchOptimalThresholdButton changed.
        }
    });

    String frequency = frequencyEditText.getText().toString();
    if (!Tools.isValidFrequency(frequency)) { // if frequency is wrong.
        Toast toast = Toast.makeText(getContext(), "Wrong frequency", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.show();
        return;
    }
    HashMap<String, String> parameters = new HashMap<>();
    parameters.put(Parameter.FREQUENCY.toString(), frequency);

    EventBus.getDefault().postSticky(new ActionEvent(Action.START_SEARCH_THRESHOLD, parameters));

}
 
開發者ID:GRnice,項目名稱:PandwarfDefenderProject,代碼行數:27,代碼來源:ThresholdFragment.java

示例2: showToast

import android.widget.Toast; //導入方法依賴的package包/類
public static void showToast(Context context, String str,int locStyle) {
    Toast toast=Toast.makeText(context, str, Toast.LENGTH_SHORT);
    //第一個參數:設置toast在屏幕中顯示的位置。我現在的設置是居中靠頂
    //第二個參數:相對於第一個參數設置toast位置的橫向X軸的偏移量,正數向右偏移,負數向左偏移
    //第三個參數:同的第二個參數道理一樣
    //如果你設置的偏移量超過了屏幕的範圍,toast將在屏幕內靠近超出的那個邊界顯示
    switch (locStyle){
        case MSG_LOCATION_CODE_CENTER:
            toast.setGravity(Gravity.CENTER, 0, 0);
            break;
        case MSG_LOCATION_CODE_TOP:
            toast.setGravity(Gravity.TOP|Gravity.CENTER, 0, 50);
            break;
        case MSG_LOCATION_CODE_BUTTOM:
            toast.setGravity(Gravity.BOTTOM|Gravity.CENTER, 0, 50);
            break;
    }
    toast.show();
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:20,代碼來源:ShowMessage.java

示例3: makeText

import android.widget.Toast; //導入方法依賴的package包/類
public static Toast makeText(Context context, CharSequence text, int duration) {
    Toast result = Toast.makeText(context, text, duration);
    result.getView().setBackgroundResource(R.drawable.tt_waterfall_refresh_bg);
    result.setGravity(Gravity.CENTER, 0, 0);
    TextView tv = (TextView) ((ViewGroup) result.getView()).getChildAt(0);
    ScreenTools tools = ScreenTools.instance(context);

    tv.setPadding(tools.dip2px(5), tools.dip2px(8), tools.dip2px(5),
            tools.dip2px(8));
    tv.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
    tv.setMinWidth(tools.dip2px(180));
    tv.setGravity(Gravity.CENTER);
    tv.setTextColor(context.getResources().getColor(android.R.color.white));
    return result;
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:16,代碼來源:PinkToast.java

示例4: showCheckmarkToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Display a checkmark toast to notify the user of a successful scan
 */
private void showCheckmarkToast(){
    // Inflate the toast layout
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_checkmark,
            (ViewGroup) findViewById(R.id.toast_layout_root));
    TextView text = (TextView) layout.findViewById(R.id.toast_text);
    text.setText(R.string.scan_successful);

    // Create the toast
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
開發者ID:RowanACM,項目名稱:RFID-Attendance,代碼行數:19,代碼來源:MainActivity.java

示例5: onLongClick

import android.widget.Toast; //導入方法依賴的package包/類
public boolean onLongClick(View v) {
    int[] screenPos = new int[2];
    getLocationOnScreen(screenPos);
    Context context = getContext();
    int width = getWidth();
    int height = getHeight();
    int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    Toast cheatSheet = Toast.makeText(context, this.mTab.getContentDescription(), 0);
    cheatSheet.setGravity(49, (screenPos[0] + (width / 2)) - (screenWidth / 2), height);
    cheatSheet.show();
    return true;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:13,代碼來源:TabLayout.java

示例6: create

import android.widget.Toast; //導入方法依賴的package包/類
public Toast create() {
    View contentView = View.inflate(context, R.layout.dialog_toast, null);
    TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);
    toast = new Toast(context);
    toast.setView(contentView);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    tvMsg.setText(msg);
    return toast;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:ToastUtil.java

示例7: showToastSavor

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * 與app色調一致的自定義Toast
 * @param context
 * @param msg 要展示的信息
 */
public static void showToastSavor(Context context, String msg) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View inflate = layoutInflater.inflate(R.layout.view_text, null);
    ((TextView) inflate.findViewById(R.id.custom_toast)).setText(msg);
    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setView(inflate);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.show();
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:16,代碼來源:ToastUtil.java

示例8: onPostExecute

import android.widget.Toast; //導入方法依賴的package包/類
protected void onPostExecute(Boolean success) {
    Toast toast = Toast.makeText(getBaseContext(), "PNG Saved", Toast.LENGTH_LONG);
    toast.setGravity(17, 0, 0);
    toast.show();
    getWindow().clearFlags(16);

}
 
開發者ID:asif-patel,項目名稱:ImageEraser,代碼行數:8,代碼來源:MainActivity.java

示例9: showPasteMessage

import android.widget.Toast; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private void showPasteMessage(String label) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    return;
  }
  final Toast toast = Toast.makeText(webView.getContext(), label, Toast.LENGTH_LONG);
  toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
  toast.show();
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:10,代碼來源:SocialSharing.java

示例10: createShort

import android.widget.Toast; //導入方法依賴的package包/類
public Toast createShort() {
    View contentView = View.inflate(context, R.layout.dialog_toast, null);
    TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);
    toast = new Toast(context);
    toast.setView(contentView);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    tvMsg.setText(msg);
    return toast;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:ToastUtil.java

示例11: onActivityResult

import android.widget.Toast; //導入方法依賴的package包/類
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case REQUEST_CONNECT_DEVICE_SECURE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                connectDevice(data, true);
            }
            break;
        case REQUEST_CONNECT_DEVICE_INSECURE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                connectDevice(data, false);
            }
            break;
        case REQUEST_ENABLE_BT:
            // When the request to enable Bluetooth returns
            if (resultCode == Activity.RESULT_OK) {
                // Bluetooth is now enabled, so set up a chat session
                setupChat();
            } else {
                // User did not enable Bluetooth or an error occurred
                Log.d(TAG, "BT not enabled");

                Toast toast = Toast.makeText(getActivity(), R.string.bt_not_enabled_leaving,
                        Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();

                getActivity().finish();
            }
    }
}
 
開發者ID:paulinog,項目名稱:SecretTalk,代碼行數:33,代碼來源:BluetoothChatFragment.java

示例12: startProtection

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Start protection, check if frequency && decibel values are regular.
 * If not a toast will be showed.
 *
 * Otherwise an event "START_PROTECTION" will be sent to the main activity.
 */
private void startProtection() {

    if (!Tools.isValidDb(dbToleranceEditText.getText().toString()) ||
            !Tools.isValidFrequency(frequencyEditText.getText().toString())) {
        Toast toast = Toast.makeText(getContext(), "wrong parameters", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.show();
        return;
    }
    refreshCurrentConfiguration();
    historyLogArrayList.clear();
    resetFragment();
    showHistoryButton.setVisibility(View.VISIBLE);
    showHistoryButton.setText(getString(R.string.no_attack_detected_flat_button));
    currentState = PROTECTION_ON_RUN;
    progressBarPandwarfRunning.setVisibility(View.VISIBLE);
    startStopProtectionButton.setText(R.string.stop_protection_text_button); // change text value
    HashMap<String, String> parameters = new HashMap<>(); // parameters will contains the frequency, db, peak tolerance & margin error values.

    parameters.put(Parameter.FREQUENCY.toString(), String.valueOf(currentConfiguration.getFrequency()));
    parameters.put(Parameter.RSSI_VALUE.toString(), String.valueOf(currentConfiguration.getDbTolerance()));
    parameters.put(Parameter.PEAK_TOLERANCE.toString(), String.valueOf(currentConfiguration.getPeakTolerance()));
    parameters.put(Parameter.MARGIN_ERROR.toString(), String.valueOf(currentConfiguration.getMarginError()));
    EventBus.getDefault().postSticky(new ActionEvent(Action.START_PROTECTION, parameters));
    addLog(HistoryLog.WARNING_LEVEL.LOW, "Protection started");

}
 
開發者ID:GRnice,項目名稱:PandwarfDefenderProject,代碼行數:34,代碼來源:GuardianFragment.java

示例13: onLongClick

import android.widget.Toast; //導入方法依賴的package包/類
@Override
public boolean onLongClick(View v) {
    final int[] screenPos = new int[2];
    getLocationOnScreen(screenPos);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    Toast cheatSheet = Toast.makeText(context, mTab.getContentDescription(), Toast.LENGTH_SHORT);
    // display below the tab
    cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, (screenPos[0] + width / 2) - screenWidth / 2, height);
    cheatSheet.show();
    return true;
}
 
開發者ID:sanyuzhang,項目名稱:CircularViewPager,代碼行數:15,代碼來源:CircularTabLayoutAdapter.java

示例14: BlueChatPress

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Shows the defined keyword used
 */
private void BlueChatPress() {
    String toastText;
    if (!mKeyword.isEmpty()) {
        toastText = "Key: " + mKeyword;
    } else {
        toastText = "Empty keyword";
    }
    Toast toast = Toast.makeText(MessageActivity.this, toastText, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    toast.show();
}
 
開發者ID:paulinog,項目名稱:SecretTalk,代碼行數:15,代碼來源:MessageActivity.java

示例15: startOver

import android.widget.Toast; //導入方法依賴的package包/類
public void startOver (View startView) {

        // Do this when you want to start over
        Toast newGame = Toast.makeText(getApplicationContext(),"Okay, here's a new game!", Toast.LENGTH_SHORT);
                    newGame.setGravity(Gravity.CENTER, 0, 0);
                    newGame.show();

        // Reset all the pieces.
        ImageView p0 = (ImageView)findViewById(R.id.p0);
        ImageView p1 = (ImageView)findViewById(R.id.p1);
        ImageView p2 = (ImageView)findViewById(R.id.p2);
        ImageView p3 = (ImageView)findViewById(R.id.p3);
        ImageView p4 = (ImageView)findViewById(R.id.p4);
        ImageView p5 = (ImageView)findViewById(R.id.p5);
        ImageView p6 = (ImageView)findViewById(R.id.p6);
        ImageView p7 = (ImageView)findViewById(R.id.p7);
        ImageView p8 = (ImageView)findViewById(R.id.p8);
        p0.setImageResource(R.drawable.coin);
        p1.setImageResource(R.drawable.coin);
        p2.setImageResource(R.drawable.coin);
        p3.setImageResource(R.drawable.coin);
        p4.setImageResource(R.drawable.coin);
        p5.setImageResource(R.drawable.coin);
        p6.setImageResource(R.drawable.coin);
        p7.setImageResource(R.drawable.coin);
        p8.setImageResource(R.drawable.coin);

        // Reset all the variables.
        turn = 0;
        gameInPlay = true;

        // Reset the array.
        for (int p = 0; p < conditions.length; p++) {
            conditions[p] = 2;
        }


    }
 
開發者ID:alaskalinuxuser,項目名稱:apps_small,代碼行數:39,代碼來源:MainActivity.java


注:本文中的android.widget.Toast.setGravity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。