1

i have a problem with my application. Basically what it does, is when i click a button, it creates 3 fields (2 editText and 1 spinner) on a scrollView. The thing works well, the only problem that im having, is related with the style, the activity bgColor is white(as the rest of the app) but, when i create elements programmatically, these elements doesnt have the look of the rest of my app. The editTexts are white with white letters (impossible to read since my bgColor is white as well) and its the same thing with the spinner. What can i do? Here is a snipet of code so you can see what im doing here.

public class AddIngredients extends Activity {
public int Count = 0;
public String[] spinnerArray = {"Gr", "kg", "Cups", "ml", "L", "oz"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addingredients);
    final TableLayout lm = (TableLayout) findViewById(R.id.TableMain);

    TableLayout.LayoutParams params = new TableLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    Button addMore = (Button)findViewById(R.id.addmore);
    addMore.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            TableRow ll = new TableRow(getApplicationContext());
            //ll.setOrientation(LinearLayout.HORIZONTAL);


            EditText product = new EditText(getApplicationContext());
            product.setHint(" Ingredient "+Count +"    ");

            // Create Button
            EditText amount = new EditText(getApplicationContext());
                // Give button an ID
                amount.setId(Count);
                amount.setHint("Quantity");

            final Button btn2 = new Button(getApplicationContext());

                btn2.setId(Count);
                btn2.setText("Remove " + Count);

            Spinner spinner = new Spinner(getApplicationContext());
            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
            spinner.setAdapter(spinnerArrayAdapter);

            ll.addView(product);
            ll.addView(amount);
            ll.addView(spinner);
            lm.addView(ll);
            Count = Count + 1;

I know my XML is working well because if i create the 3 views on my xml, they look great. PD: Thx in advance for any help! Greetings.

3 Answers 3

1

you can use

amount.setTextColor(Color.BLACK);

to set colour of text to black or any other colour
same can be used for spinner

Sign up to request clarification or add additional context in comments.

15 Comments

I did try that, the thing is that, yes, the color of the text changes, but not the line under the text (the editText line) and sadly, there is no way to do it with the spinner, at least i didnt find it. :c
you can add LayoutParams with the EditText as well and you can change the ui according to your wish
How can i do that Karan? :$
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); and add using ll.addView(amount, params);
you av=n refer to this link stackoverflow.com/questions/14199240/… if you want to remove borders of your edittext... if this do not work then tell what eactly what you want nd what is your outcome..
|
1

Here's how I set the colors of my edit text lines and other theme-related android views.

http://android-holo-colors.com/

I just picked the color and views I wanted, then unzipped them in my res folder, then set the theme according the android tutorials.

I recommend backing up your res folder first, in case you don't like the results.

Garret

2 Comments

Ok, but my whole app theme works perfect, and even the scrollview works great (if i add the elements in the xml manually), the problem comes with i create the elements programmatically :/.
As far as I know, there isn't an attribute for the edit text line color that you can change programmatically and I remember searching for it a while back. You can keep your existing theme with the method above, just add the elements created from that site to override the edit text line.
0

I had a error in my code. When creating the fields, i was using (getApplicationContext());. I fixed it using MyApplicationName.this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.