How to put the default android Styles e.g. edittext spinner etc

Asked

Viewed 957 times

2

I could use some help. My android app is in trouble, all the elements I add it plays on the screen in a different way.

Ex: when I add an Edittext it does not get the edge only shows the same when it gains focus and so for others

There’s no way to fix this if there’s no way I can do it again? Follow image below with real problem. inserir a descrição da imagem aqui

follows codes

activity_financeiro_change.xml

<Spinner
 android:layout_width="350dp"
    android:layout_height="wrap_content"
    android:id="@+id/SPAtlerarResultado"
    android:textColor="@color/font"
    android:layout_below="@+id/tvAlterarConsultor"
    android:layout_alignLeft="@+id/tvAlterarConsultor"
    android:layout_alignStart="@+id/tvAlterarConsultor"
    android:layout_marginTop="26dp"
    android:drawableRight="@drawable/spinner_triangulo"
    android:prompt="@string/textospiner"
    android:drawSelectorOnTop="true"
    />

financeiro_alterar_spinner.xml

<TextView
    android:layout_width="wrap_content"

    android:text="Resultado"
    android:textColor="@color/font"
    android:id="@+id/tvAlterarResultado"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_height="48dp"
    android:gravity="center_vertical|start"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textSize="18dp"

   />

.class

Spinner sp = (Spinner) findViewById(R.id.SPAtlerarResultado);
sp.setPrompt("Selecione um resultado");

sp.setAdapter(new FinanceiroResultadoAdapter(FinanceiroAlterar.this, resultados));

My Adapter is like this.

public View getView(int position, View convertView, ViewGroup parent) {

    FinanceiroResultado resultado = lista.get(position);
    View layout;

    if(convertView == null){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout = inflater.inflate(R.layout.financeiro_alterar_spinner, null);
    }
    else{
        layout = convertView;
    }
    TextView nome = (TextView) layout.findViewById(R.id.tvAlterarResultado);
    nome.setText(resultado.getDs_resultadofinanceiro());


    return layout;
}

1 answer

1

If this image you posted is related to your project, possibly it should be overwriting your layout, you could create a file to define the Shape you want, follow example :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<!-- background do seu shape -->

<solid android:color="#00000000" >
</solid>
 <!-- cor da borda e tamanho -->
<stroke
    android:width="1dp"
    android:color="#ffffff" >
</stroke>

<!-- aqui voce adiciona o padding desejado -->
<padding
    android:bottom="4dp"
    android:left="4dp"
    android:right="4dp"
    android:top="4dp" >
</padding>

<!-- Radius -->
<corners android:radius="5dp" >
</corners>

When you assign the layout to editText it would look something like:

<RelativeLayout
        <!-- demais configs. omitidas -->
        android:background="@layout/shapelogin" >


 <EditText
          android:id="@+id/txtUsuario"

  </EditText>
    </RelativeLayout>

Note: The layout shape changes depending on the theme you use, so the spinner of version 2.3 is not the same as version 4.4 or 5.0. One way around this is by creating a style.xml and customize in the way you think best your layout.

For your spinner you can set this when setting the Adapter something like :

adapterConexoesListView = new AdapterConexoesListView(this, android.R.layout.simple_spinner_dropdown_item, listaConexao)

EDIT: In the Constructor of your Adapter pass the new example parameter :

public AdapterConexoesListView(ConexaoSettingsSpinnerActivity context, int simpleSpinnerItem, List<Conexao> listaConexao)

Where simple_spinner_dropdown_item will be displayed in the manner below:

inserir a descrição da imagem aqui

Or you can use simple_spinner_item

inserir a descrição da imagem aqui

However you can customize letters, font size by setting your spinner layout.

  • exactly that. but how do I set this spinner layout adapting my way Spinner sp = (Spinner) findViewById(R.id.SPAtlerarResultado);&#xA; sp.setPrompt("Selecione um resultado");&#xA; sp.setAdapter(new FinanceiroResultadoAdapter(FinanceiroAlterar.this, resultados));

  • sp.setAdapter(new FinanceiroResultadoAdapter(FinanceiroAlterar.this,android.R.layout.simple_spinner_dropdown_item, resultados)); OF ERROR

  • for you to do this in your Adapter(constructor) you need to pass this argument that will be received can do so int simpleSpinnerItem because the value that comes from the R class is an int. @Klebersouza

  • @Klebersouza, it worked?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.