我有一个滚动视图按钮的列表,但是当我通过编程添加一些其他按钮的风格是不同的,我不知道为什么。 正如我们在下一张图片中看到的,添加的按钮更加黑暗,当我点击按钮时,按钮的背景变成蓝色。 但我的默认按钮是深灰色。为什么按钮样式改变时,我编程添加?
有捕获:
按钮 “6” 是XML按钮来添加。另一个是以编程方式添加的。
有我的XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/diese">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="700dp" >
<TableRow
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/one"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
</TableRow>
有我的代码添加按钮:
TableLayout SV =(TableLayout)findViewById(R.id.tableLayout1);
TableLayout.LayoutParams layoutParams = new TableLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,2200,500);
sv.setLayoutParams(layoutParams);
View view = findViewById(R.id.diese);
Diese d1 = new Diese(1,"test");
d1.addDieseToXml(sv,this);
Diese d2 = new Diese(2,"Coucou");
d2.addDieseToXml(sv,this);
Thx很多。上下文“this”引用我的ButtonActivity。
也许按钮.setActivated(真);或者出于某种原因,我更喜欢gridView以编程方式创建按钮 – ORY