【问题标题】:Android Buttons will not change my active layoutAndroid 按钮不会改变我的活动布局
【发布时间】:2015-10-11 13:27:30
【问题描述】:

我的按钮没有运动或颜色变化(他们应该这样做吗?)他们也没有按照指示做(我只编码了一个)我打算让他们改变活动布局,但他们没有这样做.以下是与该问题有关的代码。谢谢!

这是我的点击监听器的java代码:

Button lost = (Button)findViewById(R.id.lost1);
        lost.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent("com.guruguru2.lostnfound.FOUNDTEXT"));
                System.out.println("pressed");
            }
        });

以及引用该意图的清单:

<activity
            android:name=".FoundText"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.guruguru2.lostnfound.FOUNDTEXT" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

最后,带有按钮 XML 的布局(仅相关部分):

<Button
        android:id="@+id/lost1"
        android:layout_width="fill_parent"
        android:layout_height="230dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_gravity="top"
        android:layout_weight="1"
        android:text="@string/lost"
        android:textColor="@color/lostfoundtext"
        android:textColorLink="@color/white"
        android:textSize="@dimen/abc_text_size_headline_material"
        android:textStyle="bold|italic"
        android:typeface="serif" />

    <Button
        android:id="@+id/found1"
        android:layout_width="fill_parent"
        android:layout_height="230dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        android:text="Found"
         android:textColor="@color/lostfoundtext"
        android:textColorLink="@color/white"
        android:textSize="@dimen/abc_text_size_headline_material"
        android:textStyle="bold|italic"
        android:typeface="serif" />

【问题讨论】:

  • 你用这个意图做什么?

标签: java android xml eclipse android-emulator


【解决方案1】:

我刚刚在一个新项目中尝试了您的代码,它运行良好。当我单击“丢失”按钮时,它切换到新活动。按钮点击动画也播放了。我怀疑如果按钮没有播放动画并且没有按照您的预期执行,您的布局可能会出现问题。

你能验证按钮处理程序被调用了吗?尝试在处理程序中放置 System.out.println() 或使用调试器并设置断点。

附: 它不会伤害任何东西,但我知道你不需要清单中的这一行,在 Activity 内:

<action android:name="com.guruguru2.lostnfound.FOUNDTEXT" />

启动一个活动只需要活动的全名;您的活动不需要处理意图。

【讨论】:

  • 所以当它被点击时。没有任何东西输出到控制台。我添加了一条小线指示它这样做:/ 所以处理程序没有被调用。
  • 所以该按钮正在工作,但存在 a)在开始下一个活动之前大约 6 秒的极端延迟,并且 b)当下一个活动开始时,屏幕变黑并且应用程序崩溃。
  • 崩溃时的堆栈跟踪是什么?
  • 我对 DeadObjectException 没有任何经验。
【解决方案2】:

像这样打开你的活动:

Intent intent = new Intent();
intent.setAction("com.guruguru2.lostnfound.FOUNDTEXT");
startActivity(intent);

 Intent intent = new Intent(YourActivity.this, FoundText.class);
 startActivity(intent);

【讨论】:

  • 我更改了它只是为了确定,但按钮上的活动或动画仍然没有变化。
  • @alashowSo 该按钮正在工作,但存在 a)在它开始下一个活动之前大约 6 秒的极端延迟和 b)当下一个活动开始时,屏幕变黑并且应用程序崩溃。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-17
  • 1970-01-01
  • 2013-11-30
相关资源
最近更新 更多