【发布时间】:2014-09-13 18:38:51
【问题描述】:
现在我将继续更改屏幕背景颜色,同时将图像拖动到 (x,y) 坐标中,布局也应该根据它更改屏幕的不透明度级别。
我已经学习了下面的教程:
http://android-er.blogspot.in/2009/08/change-background-color-by-seekbar.html
http://android-er.blogspot.in/2012/02/animate-fade-infade-out-by-changing.html
然后通过以下程序设置进行尝试:
layout.getBackground().setAlpha(30);
代码如下:
public class MyActivity extends Activity {
public boolean status = false;
Button first,second;
LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
layout = (LinearLayout) findViewById(R.id.trans);
first = (Button) findViewById(R.id.first_theme);
second = (Button) findViewById(R.id.second_theme);
// if(status==true)
// {setTheme( android.R.style.ThemeFirst );
// }
// else
{
// setTheme( android.R.style.ThemeSecond );
// }
first.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
status = true;
layout.getBackground().setAlpha(30);
}
});
second.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
second.getBackground().setAlpha(00);
}
});
}
}
但不,它会导致我 NullPointerException 错误如果有人对此有任何想法,请帮助我的朋友。
【问题讨论】:
-
请输入您的代码。
-
请注意,setAlpha 采用介于 0 和 1 之间的浮点值,而不是 0-255
标签: android android-linearlayout opacity