如何解决如何在Android中设置吐司宽度?
| 是否有任何简单的方法可以自定义Toast
中的set width
?
谢谢,
Nital
更新:
没有这样的方法...
我终于以这种方式定制了...
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
解决方法
我使用以下方法设置烤面包的宽度和高度。
如何设置烤面包的宽度和高度
CancelProgressDialog.java
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class CancelProgressDialog extends Activity {
ProgressDialog myProgressDialog = null;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
/* Create a very simple button */
Button b = new Button(this);
this.setContentView(b);
b.setText(\"Show ProgressBar...\");
// b.setOnClickListener(myProgressBarShower);
Context context = getApplicationContext();
LayoutInflater inflater = getLayoutInflater();
View toastRoot = inflater.inflate(R.layout.customtoast,null);
TextView tv = (TextView) toastRoot.findViewById(R.id.toasttext);
tv.setWidth(200);
tv.setHeight(100);
Toast toast = new Toast(context);
toast.setView(toastRoot);
toast.show();
// toast.setText(\"I am toast\");
toast.setDuration(Toast.LENGTH_LONG);
}
}
customtoast.xml
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<TextView
xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:text=\"I am toast\"
android:textColor=\"#000000\"
android:id=\"@+id/toasttext\"
android:background=\"#ffffff\" />
谢谢
迪帕克
, 采用
Toast t = Toast.makeText(this,\"Hello\",Toast.LENGTH_SHORT);
t.setGravity(Gravity.FILL_HORIZONTAL,0);
, 您可以将其包裹在另一层布局中,它将起作用
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:orientation=\"vertical\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_gravity=\"center\"
android:id=\"@+id/container\"
android:background=\"@color/white\">
<!-- customize your width and height here -->
<LinearLayout
android:layout_width=\"200dp\"
android:layout_height=\"200dp\"
android:orientation=\"vertical\"
android:gravity=\"center\">
<ImageView
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:background=\"@drawable/ic_check_box\"/>
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:text=\"@string/message\"/>
</LinearLayout>
</LinearLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。