这是我的解决方案:
我的XML文件里面第一个活动。点击按钮后,您将被重定向到第二个有按钮的活动。我给完整的源代码:
活动1:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button nextBtn = (Button)findViewById(R.id.button1);
nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("com.ranjan.dibya.shadow.Next"));
}
});
}
}
活动2:
public class Next extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
}
}
XML的活动1:
<RelativeLayout 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:background="#f09473"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:text="Button" />
</RelativeLayout>
XML为活动2:
<RelativeLayout 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"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="This is clickable" />
</RelativeLayout>
我的清单
<activity
android:name=".Next"
android:label="@string/app_name"
android:theme="@style/Theme.MyTranslucent" >
风格:
<style name="Theme.MyTranslucent" parent="android:style/Theme.Translucent">
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.5</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:background">@android:color/transparent</item>
</style>
这对我的作品。我希望同样适用于你。
编辑:您使用的链接会导致在中心的按钮透明的活动想通了这一点由我自己:)
我甚至用getWindow()setBackgroundDrawable(新ColorDrawable(0));但它不工作 –