我正在开发一款多设备Android应用。一切都很好,但有两件事。进度对话框和吐司在android中看起来非常小但在S2中非常好。任何人都可以建议任何相同的解决方法,以增加吐司的大小和进度和责任。我已经在清单中提到屏幕支持但没有用。
答案 0 :(得分:1)
您可以创建自定义Toast,您可以在其中定义自己的布局。查看下面的代码。
XML布局,名为“custom_toast.xml”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00AAE9"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="@+id/toastImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:src="@drawable/ic_warning" />
<TextView
android:id="@+id/toastText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textColor="#FFFFFF"
android:textSize="7pt"
android:textStyle="italic" />
</LinearLayout>
</LinearLayout>
您的活动类
package com.javatechig.droid.ui;
import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button toastButton = (Button) this.findViewById(R.id.toastButton);
toastButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//create the toast object, set display duration,
Toast.makeText(getApplicationContext(), "This is a plain toast.",
Toast.LENGTH_SHORT).show();
}
});
Button customToastButton = (Button) this.findViewById(R.id.customToastButton);
customToastButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//get the LayoutInflater and inflate the custom_toast layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup)
findViewById(R.id.toast_layout_root));
//get the TextView from the custom_toast layout
TextView text = (TextView) layout.findViewById(R.id.toastText);
text.setText("This is my custom toast");
//create the toast object, set display duration,
//set the view as layout that's inflated above and then call show()
Toast t = new Toast(getApplicationContext());
t.setDuration(Toast.LENGTH_LONG);
t.setView(layout);
t.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
以下的输出
答案 1 :(得分:1)
您可以为任何类型的对话框或烤面包设置视图以进行自定义外观。下面提到了示例,同样适用于警报或进度对话框。
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate
(R.layout.custom_toast,(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text); text.setText("This is a custom toast");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout); toast.show();