如何在屏幕上显示按钮?我把它定义为
final Button nappi = (Button) findViewById(R.id.soita);
和
<Button
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="@+string/Soita"
android:id="@+id/soita"
/>
最佳答案
您需要创建要在其中显示按钮的 View 的布局。甚至像
假设您将定义存储在 res/layout 目录中名为 main.xml 的文件中。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
然后在您的 Activity 中,您需要执行以下操作:
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Replace this with the name of your xml file dictating layout
setContentView(R.layout.main);
}
}
请参阅 Hello Views 教程;很有用。 http://developer.android.com/guide/tutorials/views/index.html
如果您问的是不同的问题,例如以编程方式向现有 View 添加按钮,我不确定。在这种情况下,您可能希望按钮一开始是隐藏的,然后在需要时显示出来。
关于android - Android 屏幕的新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1498046/