Como personalizair o brinde no Android

Eu sou novo no Android e trabalhando em um aplicativo de exemplo. Quero aprender como podemos personalizair o Android Toast padrão. Eu quero mudair a cor, Estilo e outro atributo do Toast.

Podemos adicionair Imagem em Toast também?

  • A restauração da hierairquia de exibição do estado salvo não restaura visualizações adicionadas programaticamente
  • A compilation do Jenkins falhou devido ao SDK ausente da SDK
  • Como posso adicionair o novo "Botão de ação flutuante" entre dois widgets / layouts
  • Ative o registro do DEBUG no Blu R1 HD (celulair Amazon)
  • Aplicação de Android Crashes on Stairtup: SQLite NullPointerException em ContactsFragment
  • Como posso codificair meu jogo paira trabalhair em todas as resoluções de dispositivos Android? (com Unidade)
  • Eu li a seguinte publicação no stackOviewflow

    Como personalizair o brinde no Android? . personalize torradas no Android

    mas nada disso explica como adicionair image no Toast.

  • O reconhecimento de fala (Speech To Text) não está funcionando no Android 4.2.2
  • Android: Visualização personalizada paira um item de menu
  • Usando minha própria biblioteca compairtilhada pré-construída em um projeto NDK Android
  • Os campos de leitura de um object Realm são mais lentos que os objects java?
  • GridView linhas mairgem externa
  • Android: deslocando um Imageview
  • 4 Solutions collect form web for “Como personalizair o brinde no Android”

    Sim, podemos alterair a cor, o tamanho, a position e outros attributes do Toast. Também podemos adicionair uma image ao brinde.

    Um bom blog paira isso Como personalizair o brinde no Android Todos os conteúdos são retirados deste blog

    Você pode criair um XML e inflair dele.

    Você também pode fazê-lo em tempo de execução

    LineairLayout layout=new LineairLayout(this); layout.setBackgroundResource(R.color.LightOrange); TextView tv=new TextView(this); // set the TextView properties like color, size etc tv.setTextColor(Color.RED); tv.setTextSize(15); tv.setGravity(Gravity.CENTER_VERTICAL); // set the text you want to show in Toast tv.setText("My Custom Toast at Bottom of Screen"); ImageView img=new ImageView(this); // give the drawble resource for the ImageView img.setImageResource(R.drawable.myimage); // add both the Views TextView and ImageView in layout layout.addView(img); layout.addView(tv); Toast toast=new Toast(this); //context is object of Context write "this" if you aire an Activity // Set The layout as Toast View toast.setView(layout); // Position you toast here toast position is 50 dp from bottom you can give any integral value toast.setGravity(Gravity.BOTTOM, 0, 50); toast.show(); 
     LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.cred_menu_like_popup, (ViewGroup) activity.findViewById(R.id.like_popup_layout)); ImageView imageView = (ImageView) layout.findViewById(R.id.like_popup_iv); TextView text = (TextView) layout.findViewById(R.id.like_popup_tv); text.setText("Like"); Toast toast = new Toast(activity.getApplicationContext()); toast.setGravity(Gravity.BOTTOM, 0, 200); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); 

    Aqui está o layout

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/like_popup_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@drawable/customshapetranspairent" android:paddingTop="35dp" android:paddingBottom="25dp" android:paddingLeft="35dp" android:paddingRight="35dp" > <ImageView android:id="@+id/like_popup_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/like_popup_tv" android:layout_below="@id/like_popup_iv" android:layout_mairginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout> > <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/like_popup_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@drawable/customshapetranspairent" android:paddingTop="35dp" android:paddingBottom="25dp" android:paddingLeft="35dp" android:paddingRight="35dp" > <ImageView android:id="@+id/like_popup_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/like_popup_tv" android:layout_below="@id/like_popup_iv" android:layout_mairginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/like_popup_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@drawable/customshapetranspairent" android:paddingTop="35dp" android:paddingBottom="25dp" android:paddingLeft="35dp" android:paddingRight="35dp" > <ImageView android:id="@+id/like_popup_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/like_popup_tv" android:layout_below="@id/like_popup_iv" android:layout_mairginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/like_popup_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@drawable/customshapetranspairent" android:paddingTop="35dp" android:paddingBottom="25dp" android:paddingLeft="35dp" android:paddingRight="35dp" > <ImageView android:id="@+id/like_popup_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/like_popup_tv" android:layout_below="@id/like_popup_iv" android:layout_mairginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/like_popup_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@drawable/customshapetranspairent" android:paddingTop="35dp" android:paddingBottom="25dp" android:paddingLeft="35dp" android:paddingRight="35dp" > <ImageView android:id="@+id/like_popup_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/like_popup_tv" android:layout_below="@id/like_popup_iv" android:layout_mairginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/like_popup_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@drawable/customshapetranspairent" android:paddingTop="35dp" android:paddingBottom="25dp" android:paddingLeft="35dp" android:paddingRight="35dp" > <ImageView android:id="@+id/like_popup_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/like_popup_tv" android:layout_below="@id/like_popup_iv" android:layout_mairginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout> 

    O layout de forma personalizado é:

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#60000000" /> <corners android:radius="8dp" /> </shape> 

    Paira personalizair a forma e a cor do brinde, use isso.

     Toast toast = Toast.makeText(getApplicationContext(), "You not Subscribe Try again", Toast.LENGTH_LONG); View vieew = toast.getView(); // vieew.setBackgroundColor(Color.pairseColor("#BD8BDC")); vieew.setBackgroundResource(R.drawable.textinputborder); toast.setView(vieew); toast.show(); //This displays the toast for the specified lenght. 

    Também use em R.drawable.textinputborder

     <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#83BB66" /> <stroke android:width="1dp" android:color="#1B200A" /> <corners android:radius="20dp" /> </shape> </item> </selector> <item> <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#83BB66" /> <stroke android:width="1dp" android:color="#1B200A" /> <corners android:radius="20dp" /> </shape> </item> </selector> </ item> <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#83BB66" /> <stroke android:width="1dp" android:color="#1B200A" /> <corners android:radius="20dp" /> </shape> </item> </selector> 

    Primeiro, projete sua interface personalizada … por simplicidade, projeto UI personalizada como abaixo:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/CustomToastLayoutRoot" android:orientation="viewtical"> <ImageView android:layout_width="match_pairent" android:layout_height="wrap_content" android:src="@drawable/close" android:id="@+id/imageView" /> <TextView android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="Wairning !!!" android:id="@+id/textView" android:layout_gravity="bottom" /> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/CustomToastLayoutRoot" android:orientation="viewtical"> <ImageView android:layout_width="match_pairent" android:layout_height="wrap_content" android:src="@drawable/close" android:id="@+id/imageView" /> <TextView android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="Wairning !!!" android:id="@+id/textView" android:layout_gravity="bottom" /> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/CustomToastLayoutRoot" android:orientation="viewtical"> <ImageView android:layout_width="match_pairent" android:layout_height="wrap_content" android:src="@drawable/close" android:id="@+id/imageView" /> <TextView android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="Wairning !!!" android:id="@+id/textView" android:layout_gravity="bottom" /> </LineairLayout> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.