我有一个按钮,如下所示:
<Button
android:text="Submit"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
Run Code Online (Sandbox Code Playgroud)
在我的onCreate()活动中,我这样调用Button01:
setContentView(R.layout.main);
View Button01 = this.findViewById(R.id.Button01);
Button01.setOnClickListener(this);
Run Code Online (Sandbox Code Playgroud)
应用程序中有一个背景,我想在此提交按钮上设置不透明度.如何为此视图设置不透明度?这是我可以在java端设置的东西,还是我可以在main.xml文件中设置?
在java方面,我试过Button01.mutate().SetAlpha(100),但它给了我一个错误.
我最初的目标是模态对话框,但是你知道,Android不支持这种类型的对话框.或者,构建以对话为主题的活动可能会奏效.
这是代码,
public class DialogActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Dialog);
super.onCreate(savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
Button yesBtn = new Button(this);
yesBtn.setText("Yes");
yesBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DialogActivity.this.finish();
}
});
this.setContentView(yesBtn);
}
Run Code Online (Sandbox Code Playgroud)
然而,背景总是黑色,这真的令人困惑.人们遇到同样的问题,
http://code.google.com/p/android/issues/detail?id = 4394
我只是想让它看起来更像用户对话.那么,如何使这个DialogActivity透明,永远不会覆盖底层屏幕?
谢谢.
这就是我创作风格的方式
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)