0
我用對話的主題,以顯示我的活動我可以通過編程方式更改android對話框主題背景顏色嗎?
<activity
android:name=".MyDialog"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar" >
</activity>
本次活動搜索條。
alphaSeek=(SeekBar)findViewById(R.id.seekbar_alpha);
alphaSeek.setOnSeekBarChangeListener(this);
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
???=progress;
}
我可以使用seekbar值來改變對話框背景的顏色嗎?
更新:
基於第一個答案,我重寫程序,註釋行是以前版本的我試過了。但新版本與前一版本效果完全相同,它只改變對話框中的顏色,而不改變對話框的背景。
int alpha=0;
int red=0;
int green=0;
int blue=0;
SeekBar alphaSeek;
LinearLayout myActivityLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mydialog);
myActivityLayout = (LinearLayout) findViewById(R.id.MyActivityLayout);
alphaSeek=(SeekBar)findViewById(R.id.seekbar);
alphaSeek.setOnSeekBarChangeListener(this);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
String hex = String.format("%02x%02x%02x%02x", alpha, red, green, blue);
int color=(int)Long.parseLong(hex,16);
//ColorDrawable cd=new ColorDrawable(color);
//getWindow().setBackgroundDrawable(cd);
myActivityLayout.setBackgroundColor(color);
}
版式XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/MyActivityLayout"
tools:context="com.MyDialog">
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:id="@+id/seekbar"
android:layout_gravity="center_horizontal" />
</LinearLayout>
的AndroidManifest.xml
<activity
android:name=".MyDialog"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar" >
</activity>