我有2个文件:main_activity.xml和home.xml。我在main_activity.xml中做了一个按钮
这是代码片段:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/splash_background"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="43dp"
android:onClick="home"
android:text="Home" />
</RelativeLayout>
然后,我有了home.xml。我想要按钮打开home.xml。我怎样才能做到这一点?
我不知道任何Java,而且是Android开发的新手。
这是我的home.xml下面:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/app_bg"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
下面是我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.idozer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.idozer.SplashActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.idozer.MainActivity"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
这就是我所拥有的。请回复,告诉我在哪里添加代码,例如目录或代码片段之间。
参考方案
要管理android中的点击活动,您可以执行以下操作
OnClickListener
public class MainActivity extends Activity implements OnClickListener
Button btn = (Button) findViewById(R.id.btnPlay);
btn
变量,如下所示
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myClick(v); /* my method to call new intent or activity */
}
});
public void myClick(View v) {
Intent intent = new Intent(**this, Swipe.class**);
startActivity(intent);// for calling the activity
}
您还需要在android manifest
中注册您的活动(.java),如下所示
<activity
android:name=".Swipe"
android:screenOrientation="landscape" >
</activity>
在Android Studio中设计可滚动内容时应遵循的方法是什么? - java我正在约束布局中设计我的应用程序,并将其放置在“滚动视图”下。我想放置更多的Card Views,但是在xml文件的预览中没有放置空间。当布局已满时,我应该在哪里拖放Buttons,TextViews等?我已经处理了文本的滚动视图,但这是另外一回事。我知道我只能输入代码,但是当内容超出定义的屏幕尺寸时,我将无法看到我正在设计的内容时,我将很难这样做。(如果您…
android studio的设计预览中的布局为空 - java我一直在从事一个项目,有一天我的布局在android studio设计中显得空白。我已经尝试过放置“ Base”。在文件style.xml中的“ Theme.AppCompat.Light.DarkActionBar”之前,我还尝试清理项目并使缓存/重新启动无效,但没有任何效果。我在manifest.xml中有此代码<?xml version=…
Android:如何为wrap_content设置高度动画? - java我需要使用ValueAnimator来使用户拖动特定视图时出现自定义“放置字段”。 (我想将字段从gone, height = 0更改为visible, height = wrap_content)。我已经尝试过以下问题的解决方案:How to animate to wrap_content?当我在单个TextView上使用它时,答案就起作用了,但是当我尝试…
AppCompat不支持当前主题 - java我的应用在Android N上运行正常,但在Android M上的setContentView(R.layout.activity_main)崩溃: Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { w…
为什么我的应用在启动时总是崩溃-Android - java刚刚遵循了有关如何制作按钮和活动的youtube指南。我按照他的代码减小字体大小,并且在启动时一直崩溃。有人知道为什么吗?public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { su…