1

アプリケーションに問題があります。基本的には、ボタンをクリックすると、scrollView に 3 つのフィールド (2 つの editText と 1 つのスピナー) が作成されます。うまく機能します。私が抱えている唯一の問題はスタイルに関連しています。アクティビティbgColorは(アプリの残りの部分と同様に)白ですが、プログラムで要素を作成すると、これらの要素は私の残りの部分の外観を持っていませんアプリ。editTexts は白い文字で白く (私の bgColor も白なので読むことができません)、スピナーと同じです。私に何ができる?ここにコードのスニペットがあるので、ここで何をしているのかを見ることができます。

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;

XML で 3 つのビューを作成すると見栄えがよくなるので、XML がうまく機能していることはわかっています。PD: 助けが必要な場合は事前に Thx! ご挨拶。

4

3 に答える 3

1

編集テキスト行とその他のテーマ関連の Android ビューの色を設定する方法を次に示します。

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

必要な色とビューを選択し、それらを res フォルダーに解凍し、Android チュートリアルに従ってテーマを設定しました。

結果が気に入らない場合に備えて、最初に res フォルダーをバックアップすることをお勧めします。

ギャレット

于 2014-05-13T16:27:10.343 に答える
1

あなたが使用することができます

amount.setTextColor(Color.BLACK);

テキストの色を黒または他の色に設定する
には、スピナーに使用できます

于 2014-05-13T16:06:46.140 に答える
0

コードにエラーがありました。フィールドを作成するとき、私は (getApplicationContext());. を使って直しましたMyApplicationName.this

于 2014-05-15T11:46:31.627 に答える