本文整理汇总了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));
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
}
}
示例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");
}
示例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;
}
示例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();
}
示例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;
}
}