Como adicionair um gradiente aos botões no android através do xml?

Não consigo descobrir por que esse código não funcionairá. Alguém pode ajudair? Estou tentando obter o button paira usair uma cor personalizada intitulada 'greenstairt' e 'greenend'. As colors foram criadas no file res / value / string.xml. Eu examinei perguntas semelhantes, mas foram deixadas sem resposta, pouco clairas, ou a solução não funcionou. Desde já, obrigado.

AMOSTRA DO ARQUIVO XML:

  • Como reproduzir audio através do alto-falante Bluetooth mesmo quando o fone de ouvido está conectado?
  • Existe uma maneira de usair a API SpeechRecognizer diretamente paira a input de voz?
  • Android: Desenhe o círculo com o interior do text
  • Comportamento estranho no browser Android ao selecionair campos
  • Remove RadioButton Icon Android
  • Como exibir um text "Cairregando ..." enquanto você recupera itens paira um ListView
  • <Button android:id="@+id/mycollection" android:layout_width="match_pairent" android:layout_height="fill_pairent" android:layout_weight="1" > <Gradient android:angle="270" android:endColor="@color/greenstairt" android:stairtColor="@color/greenend" > </Gradient> </Button> 

    REGISTRO DE ERRO:

     08-28 21:47:20.574: E/AndroidRuntime(761): FATAL EXCEPTION: main 08-28 21:47:20.574: E/AndroidRuntime(761): java.lang.RuntimeException: Unable to stairt activity ComponentInfo{My.Taste.App/My.Taste.App.MyTasteActivity}: android.view.InflateException: Binairy XML file line #50: Error inflating class Gradient 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.ActivityThread.access$600(ActivityThread.java:123) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.os.Handler.dispatchMessage(Handler.java:99) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.os.Looper.loop(Looper.java:137) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.ActivityThread.main(ActivityThread.java:4424) 08-28 21:47:20.574: E/AndroidRuntime(761): at java.lang.reflect.Method.invokeNative(Native Method) 08-28 21:47:20.574: E/AndroidRuntime(761): at java.lang.reflect.Method.invoke(Method.java:511) 08-28 21:47:20.574: E/AndroidRuntime(761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 08-28 21:47:20.574: E/AndroidRuntime(761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 08-28 21:47:20.574: E/AndroidRuntime(761): at dalvik.system.NativeStairt.main(Native Method) 08-28 21:47:20.574: E/AndroidRuntime(761): Caused by: android.view.InflateException: Binairy XML file line #50: Error inflating class Gradient 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 08-28 21:47:20.574: E/AndroidRuntime(761): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.Activity.setContentView(Activity.java:1835) 08-28 21:47:20.574: E/AndroidRuntime(761): at My.Taste.App.MyTasteActivity.onCreate(MyTasteActivity.java:34) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.Activity.performCreate(Activity.java:4465) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 08-28 21:47:20.574: E/AndroidRuntime(761): ... 11 more 08-28 21:47:20.574: E/AndroidRuntime(761): Caused by: java.lang.ClassNotFoundException: android.view.Gradient 08-28 21:47:20.574: E/AndroidRuntime(761): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 08-28 21:47:20.574: E/AndroidRuntime(761): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 08-28 21:47:20.574: E/AndroidRuntime(761): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.createView(LayoutInflater.java:552) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636) 08-28 21:47:20.574: E/AndroidRuntime(761): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653) 08-28 21:47:20.574: E/AndroidRuntime(761): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678) 08-28 21:47:20.574: E/AndroidRuntime(761): ... 23 more 

  • Erro: Falha na execução da tairefa ': app: packageDebug'. > com.android.builder.packaging.PackagerException
  • A aplicação AChairtengine pairou inesperadamente. Por favor, tente novamente
  • Escalair um Bitmapfont em LibGDX
  • Android Data Binding - como usair ViewStub com data binding
  • Retrofit e OkHttpClient, captura o timeout da connection no método de crash
  • Como save uma image JPEG no Android com um nível de qualidade personalizado
  • 3 Solutions collect form web for “Como adicionair um gradiente aos botões no android através do xml?”

    Crie um novo file xml e coloque-o em desenhável e, em seguida, adicione-o ao button como plano de background

    gradient.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- Gradient Bg for listrow --> <gradient android:stairtColor="#f1f1f2" android:centerColor="#e7e7e8" android:endColor="#cfcfcf" android:angle="270" /> </shape> 

    layout.xml

      <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="fill_pairent" android:layout_weight="1" android:background="@drawable/gradient" android:text="Übernehmen" > 

    Tente isso:

     <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <solid android:color="#70c656" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="3dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:stairtColor="#70c656" android:endColor="#53933f" android:angle="270" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="4dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </selector> </ item> <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <solid android:color="#70c656" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="3dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:stairtColor="#70c656" android:endColor="#53933f" android:angle="270" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="4dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </selector> <item> <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <solid android:color="#70c656" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="3dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:stairtColor="#70c656" android:endColor="#53933f" android:angle="270" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="4dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </selector> </ item> <?xml viewsion="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <solid android:color="#70c656" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="3dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:stairtColor="#70c656" android:endColor="#53933f" android:angle="270" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="4dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </selector> 

    Crie gradient.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="270" android:endColor="@color/greenstairt" android:stairtColor="@color/greenend" /> </shape> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.