我正在创建一个简单的应用程序,我试图显示标签,但它拒绝显示。这是android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="r.gabriel.ecuacionesdesegundogrado" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:label="Ecuación de Segundo Grado">
<activity
android:name=".MainActivity"
android:label="Ecuación de Segundo Grado">
<intent-filter android:label="Ecuación de Segundo Grado">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
ActivityMain:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@color/custom_grey" >
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="@string/custom_instructions"
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"/>
</TableRow>
<!-- input a -->
<TableRow
android:weightSum="100">
<TextView
android:text="@string/custom_a"
android:layout_width="0dp"
android:layout_weight="40"/>
<EditText
android:id="@+id/inputA"
android:hint="@string/custom_dummyText"
android:layout_width="0dp"
android:layout_weight="60"/>
</TableRow>
<!-- input b -->
<TableRow
android:weightSum="100">
<TextView
android:text="@string/custom_b"
android:layout_width="0dp"
android:layout_weight="40"/>
<EditText
android:id="@+id/inputB"
android:hint="@string/custom_dummyText"
android:layout_width="0dp"
android:layout_weight="60"/>
</TableRow>
<!-- input c -->
<TableRow
android:weightSum="100">
<TextView
android:text="@string/custom_c"
android:layout_width="0dp"
android:layout_weight="40"/>
<EditText
android:id="@+id/inputC"
android:hint="@string/custom_dummyText"
android:layout_width="0dp"
android:layout_weight="60"/>
</TableRow>
<!-- answer -->
<TableRow
android:layout_weight="1"
android:weightSum="100"
android:layout_height="wrap_content">
<TextView
android:text="@string/custom_solution"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="100"
android:gravity="center"
android:textSize="25sp"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"/>
</TableRow>
</TableLayout>
</LinearLayout>
在android studio预览版中,不会显示android:标签,就像在物理设备和模拟器上运行一样。
答案 0 :(得分:0)
以下是在应用启动时只显示字符串的代码。试试这个。如果可行,请尝试在XML布局文件中添加TableLayout。
<强> ActivityMain.java 强>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText("Ecuación de Segundo Grado");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是布局文件 activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@color/custom_grey" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView1"
android:gravity="center_horizontal"
android:textSize="22sp"/>
</LinearLayout>
<强> menu_main.xml 强>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item android:id="@+id/main_menu"
android:title="Ecuación de Segundo Grado"
app:showAsAction="ifRoom"/>
</menu>