멀티 컬러 토스트가 필요합니다. 이처럼 :안드로이드 토스트 멀티 컬러
나는 사용자 정의 토스트를 만들기 위해 XML로 레이아웃을 변경하는 방법에 대한 다른 자습서 보았다, 그러나 그들 중 누구도이 같은 다른 색상을 추가 설명이 없습니다.
어떻게하면됩니까?
================================
답변
=== ===============
모든 도움을 사용하여 색상 토스트를 만드는 간단한 방법()을 고안했습니다. 전화하기가 더 쉽다.
고해상도/레이아웃/toast_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingBottom="6dp"
android:paddingTop="6dp"
android:background="#DAAA"
>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
SRC/PROJECTNAME/FILENAME.java
// Color Toast(String1,String2,Color)
// Toastbackground = White
// String1 = Dark Gray
// String2 - **CASE SENSITIVE**
// = "same" = Dark Gray, or
// = "purple" = Purple, or
// = "orange" = Orange
public void CToast(String t1, String t2, String c) {
if (c == "same") {
c = "444444";
} else if (c == "purple") {
c = "6600FF";
} else if (c == "orange") {
c = "ffcc00";
}
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView textCToast = (TextView) layout.findViewById(R.id.text);
String text2 = "<font color=#444444>" + t1 + "</font> <font color=#" + c + ">" + t2 + "</font";
textCToast.setText(Html.fromHtml(text2));
Toast toast = new Toast(this);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
희망이 도움이! 모두에게 감사합니다
이것은 제가 제안한 것입니다 만, copypastable 코드를 가지고 있습니다 : +1 – Shark