解决方案 »
- 魅族MX2锁屏效果
- GC_FOR_MALLOC freed 9803 objects 求解
- 使用过java反射的帮忙一下:如何通过反射获取apk中的方法
- Android下的HttpClient上传图片
- 请问如何使用HTTPClient在多线程的情况下保证cookies各自独立?
- 问Eclips下运行helloworld,弹出手机模拟器上什么也没有选择,怎么回事?
- android项目报Json空错误,但是这个项目别人运行不出错,我电脑生成的apk安装也会出现停止,求教为什么
- 安卓加密软件
- 怎么用android studio测试工程
- android studio安装完后每次出现两个模拟器并要求装大量SDK运行缓慢
- android 4.2 蓝牙BluetoothManagerService
- Zxing-二维码扫描问题
这个view没看到你用啊.
public class Fx extends Activity {
//声明Button对象
Button button_regist;
Button button_login;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fx);
/*--------------按钮regist----------------*/
button_regist = (Button)findViewById(R.id.btn_regist);
button_regist.setOnClickListener(new btn_registOnclick());
}
/*-------------------------regist监听器--------------------------------*/
class btn_registOnclick implements OnClickListener{
ProgressDialog r_Dialog;
LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
final View registView = regist_Inflater.inflate(R.layout.regist, null);
AlertDialog registDlg = new AlertDialog.Builder(Fx.this).
setTitle("请注册").
setView(registView).
setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton1) {
// TODO Auto-generated method stub
r_Dialog = ProgressDialog.show(Fx.this, "请等待...", "正在为您注册...",true);
new Thread(){
public void run(){
try{
sleep(3000);
}
catch(Exception e){
e.printStackTrace();
}
finally{
LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
View fxView = regist_Inflater.inflate(R.layout.activity_fx, null);
fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);//未报错,但是背景没有变黑
r_Dialog.dismiss();
}
}
}.start();
}
}).
setNegativeButton("取消",null).
create();//创建登录对话框
public void onClick(View v){
registDlg.show();//显示登录对话框
}
}
}
你activity没有setContentView()吗,为什么还要重新inflate一个view,直接就findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK)啊
代码真乱
public class Fx extends Activity {
//声明Button对象
Button button_regist;
Button button_login;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fx);
/*--------------按钮regist----------------*/
button_regist = (Button)findViewById(R.id.btn_regist);
button_regist.setOnClickListener(new btn_registOnclick());
}
/*-------------------------regist监听器--------------------------------*/
class btn_registOnclick implements OnClickListener{
ProgressDialog r_Dialog;
LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
final View registView = regist_Inflater.inflate(R.layout.regist, null);
AlertDialog registDlg = new AlertDialog.Builder(Fx.this).
setTitle("请注册").
setView(registView).
setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton1) {
// TODO Auto-generated method stub
r_Dialog = ProgressDialog.show(Fx.this, "请等待...", "正在为您注册...",true);
new Thread(){
public void run(){
try{
sleep(3000);
}
catch(Exception e){
e.printStackTrace();
}
finally{
LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
View fxView = regist_Inflater.inflate(R.layout.activity_fx, null);
fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);//未报错,但是背景没有变黑
r_Dialog.dismiss();
}
}
}.start();
}
}).
setNegativeButton("取消",null).
create();//创建登录对话框
public void onClick(View v){
registDlg.show();//显示登录对话框
}
}
}这是layout下的布局文件<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/info"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:id="@+id/btn_login"
android:text="@string/fx_login"
android:textSize="30dp"
android:layout_width="180dp"
android:layout_height="100dp"
android:layout_gravity="left"
android:visibility="visible"
>
</Button>
<Button
android:id="@+id/btn_regist"
android:text="@string/fx_regist"
android:textSize="30dp"
android:layout_width="180dp"
android:layout_height="100dp"
android:layout_gravity="right"
>
</Button>
</LinearLayout>
</RelativeLayout>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fx);
button_login = (Button)findViewById(R.id.btn_login);
...
你activity没有setContentView()吗,为什么还要重新inflate一个view,直接就findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK)啊这样改了,帮我再看看,还是不对