java应用程序主题在预览中显示,但不在手机上显示
我在安卓 studio中有一个计算器应用程序,它运行得非常好,但我选择了一个主题Material.Voice
,它会显示在预览中。但当我运行时,应用程序会回到常规主题。我该如何解决这个问题?这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:roundIcon="@mipmap/ic_launcher_round"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity 安卓:name=".MainActivity">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的样式文件:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
这是我的布局活动主文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical"
>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:baselineAligned="false">
<LinearLayout
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:orientation="vertical"
安卓:padding="5dp">
<EditText
安卓:id="@+id/number1"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:ems="10"
安卓:hint="number1"
安卓:inputType="number" />
<EditText
安卓:id="@+id/number2"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:ems="10"
安卓:hint="number2"
安卓:inputType="number" />
</LinearLayout>
<LinearLayout
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:orientation="horizontal">
<LinearLayout
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:padding="5dp">
<ToggleButton
安卓:id="@+id/switch2"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:background="#fed136"
安卓:text="Radians"/>
<TextView
安卓:id="@+id/textView9"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="Radians"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/switch3" />
</LinearLayout>
<LinearLayout
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:padding="5dp">
<ToggleButton
安卓:id="@+id/switch3"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Degree"
安卓:background="#fed136" />
<TextView
安卓:id="@+id/textView10"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="Degrees"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/switch3" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
安卓:id="@+id/sum"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:textSize="20sp"></TextView>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:layout_marginTop="20dp">
<Button
安卓:id="@+id/button"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="+"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button2"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="-"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button3"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="x"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button4"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="/"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button5"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="SQ"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button6"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="SR"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
</LinearLayout>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal">
<Button
安卓:id="@+id/button8"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="C"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button9"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="E"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button10"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="%"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button18"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="sin"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button19"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="cos"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
<Button
安卓:id="@+id/button20"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_weight="1"
安卓:text="tan"
安卓:background="#fed136"
安卓:layout_margin="5dp"/>
</LinearLayout>
<Button
安卓:id="@+id/cube"
安卓:layout_width="48dp"
安卓:layout_height="50dp"
安卓:background="#fed136"
安卓:text="CU"
tools:text="CU" />
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="53dp"
安卓:orientation="horizontal">
<TextView
安卓:id="@+id/textView8"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_alignParentStart="true"
安卓:layout_alignParentTop="true"
安卓:layout_marginStart="90dp"
安卓:layout_marginTop="0dp"
安卓:textSize="33sp"
安卓:layout_alignParentLeft="true"
安卓:layout_marginLeft="90dp" />
</LinearLayout>
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_marginTop="15dp">
<RatingBar
安卓:id="@+id/ratingBar"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:numStars="5"
安卓:rating="5"
安卓:stepSize="5"
安卓:layout_alignParentBottom="true"
安卓:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>
这是我的活动主着陆文件(当您将手机转向一侧时):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical"
>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:baselineAligned="false">
<LinearLayout
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:orientation="vertical"
安卓:padding="5dp">
<EditText
安卓:id="@+id/number1"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:ems="10"
安卓:hint="number1"
安卓:inputType="number" />
<EditText
安卓:id="@+id/number2"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:ems="10"
安卓:hint="number2"
安卓:inputType="number" />
</LinearLayout>
<LinearLayout
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:orientation="horizontal">
<LinearLayout
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:padding="5dp">
<ToggleButton
安卓:id="@+id/switch2"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:background="#fed136"
安卓:text="Radians"/>
<TextView
安卓:id="@+id/textView9"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="Radians"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/switch3" />
</LinearLayout>
<LinearLayout
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:padding="5dp">
<ToggleButton
安卓:id="@+id/switch3"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Degree"
安卓:background="#fed136" />
<TextView
安卓:id="@+id/textView10"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="Degrees"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/switch3" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginTop="20dp"
安卓:orientation="horizontal">
<Button
安卓:id="@+id/button"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="+" />
<Button
安卓:id="@+id/button2"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="-" />
<Button
安卓:id="@+id/button3"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="x" />
<Button
安卓:id="@+id/button4"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="/" />
<Button
安卓:id="@+id/button5"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="SQ" />
<Button
安卓:id="@+id/button6"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="SR" />
</LinearLayout>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal">
<Button
安卓:id="@+id/button8"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="C" />
<Button
安卓:id="@+id/button9"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="E" />
<Button
安卓:id="@+id/button10"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="%" />
<Button
安卓:id="@+id/button18"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="sin" />
<Button
安卓:id="@+id/button19"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="cos" />
<Button
安卓:id="@+id/button20"
安卓:layout_width="0dp"
安卓:layout_height="50dp"
安卓:layout_margin="5dp"
安卓:layout_weight="1"
安卓:background="#fed136"
安卓:text="tan" />
</LinearLayout>
<Button
安卓:id="@+id/cube"
安卓:layout_width="98dp"
安卓:layout_height="50dp"
安卓:background="#fed136"
安卓:text="CU"
tools:text="CU" />
<TextView
安卓:id="@+id/sum"
安卓:layout_width="444dp"
安卓:layout_height="wrap_content"
安卓:textSize="20sp">
</TextView>
<TextView
安卓:id="@+id/textView8"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textSize="33sp" />
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_marginTop="15dp">
<RatingBar
安卓:id="@+id/ratingBar"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:numStars="5"
安卓:rating="5"
安卓:stepSize="5"
安卓:layout_alignParentBottom="true"
安卓:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>
哦,为了以防万一,这是我的java文件:
package com.example.lenovouser.calculatoraghav;
//IMPORT
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.os.Bundle;
import 安卓.view.View;
import 安卓.widget.Button;
import 安卓.widget.EditText;
import 安卓.widget.TextView;
import 安卓.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
// ASSIGNING THE NAMES OR VARIABLES
TextView result, textView8;
EditText number1, number2;
Button add,subtract,divide,multiply,squareroot,square,cube,clear,Exponent,percent,sin
d, cosd, tand;
ToggleButton switch2, switch3;
double resultnum;
int num1,num2,num3;
boolean radient, degree;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//ASSIGNING THE VARIABLES TO THE ANDROID WIDGETS.
result = (TextView)findViewById(R.id.sum);
number1 = (EditText)findViewById(R.id.number1);
number2 = (EditText)findViewById(R.id.number2);
add = (Button)findViewById(R.id.button);
subtract = (Button)findViewById(R.id.button2);
multiply = (Button)findViewById(R.id.button3);
divide = (Button)findViewById(R.id.button4);
squareroot =(Button)findViewById(R.id.button6);
square = (Button)findViewById(R.id.button5);
clear = (Button)findViewById(R.id.button8);
Exponent = (Button)findViewById(R.id.button9);
percent = (Button)findViewById(R.id.button10);
sind = (Button)findViewById(R.id.button18);
cosd = (Button)findViewById(R.id.button19);
tand = (Button)findViewById(R.id.button20) ;
switch2 = (ToggleButton) findViewById(R.id.switch2);
switch3 = (ToggleButton) findViewById(R.id.switch3);
textView8 = (TextView)findViewById(R.id.textView8);
cube = (Button)findViewById(R.id.cube);
add.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//ADD
num1 = Integer.parseInt(number1.getText() .toString());
num2 = Integer.parseInt(number2.getText() .toString());
resultnum = num1 + num2;
result.setText(String.valueOf(resultnum));
}
});
subtract.setOnClickListener(new View.OnClickListener(){
//SUBTRACT
@Override
public void onClick(View v){
num1 = Integer.parseInt(number1.getText() .toString());
num2 = Integer.parseInt(number2.getText() .toString());
resultnum = num1 - num2;
result.setText(String.valueOf(resultnum));
}
});
multiply.setOnClickListener(new View.OnClickListener(){
//MULTIPLY
@Override
public void onClick(View v){
num1 = Integer.parseInt(number1.getText() .toString());
num2 = Integer.parseInt(number2.getText() .toString());
resultnum = num1 * num2;
result.setText(String.valueOf(resultnum));
}
});
divide.setOnClickListener(new View.OnClickListener(){
//DIVIDE
@Override
public void onClick(View v){
num1 = Integer.parseInt(number1.getText() .toString());
num2 = Integer.parseInt(number2.getText() .toString());
resultnum = num1 / num2;
result.setText(String.valueOf(resultnum));
}
});
squareroot.setOnClickListener(new View.OnClickListener(){
//SQUAREROOT
@Override
public void onClick(View v){
num1 = Integer.parseInt(number1.getText() .toString());
resultnum = (Math.sqrt(num1));
result.setText(String.valueOf(resultnum));
}
});
square.setOnClickListener(new View.OnClickListener(){
//SQUARE
@Override
public void onClick(View v){
num1 = Integer.parseInt(number1.getText() .toString());
resultnum = num1*num1;
result.setText(String.valueOf(resultnum));
}
});
cube.setOnClickListener(new View.OnClickListener(){
//SQUARE
@Override
public void onClick(View v){
num1 = Integer.parseInt(number1.getText() .toString());
resultnum = num1*num1*num1;
result.setText(String.valueOf(resultnum));
}
});
clear.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//CLEAR
num1 = (0);
num2 = (0);
num3 = (0);
number1.setText("");
number2.setText("");
//txt.setText("");
resultnum = 0;
result.setText(String.valueOf(resultnum));
}
});
Exponent.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//EXPONENT
int p = Integer.parseInt(number1.getText() .toString());
int e = Integer.parseInt(number2.getText() .toString());
resultnum = (Math.pow((double)p, (double)e));
result.setText(String.valueOf(resultnum));
}
});
percent.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//PERCENT
Double percentage =
Double.valueOf(number1.getText().toString());
Integer num2 = Integer.parseInt(number2.getText().toString());
Double resultnum = percentage * num2 / 100;
result.setText(String.valueOf(resultnum));
}
});
sind.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//SIN num2
if (degree)
{
num1 = Integer.parseInt(number1.getText().toString());
//num2 = Integer.parseInt(number2.getText().toString());
resultnum = Math.sin(Math.toDegrees(num1));
result.setText(String.valueOf(resultnum));
}
if (radient){
num1 = Integer.parseInt(number1.getText().toString());
//num2 = Integer.parseInt(number2.getText().toString());
resultnum = Math.sin(Math.toRadians(num1));
result.setText(String.valueOf(resultnum));
if (!degree)
{
}
if (!radient){
}
}
}
});
cosd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//COS num2
if (degree)
{
num1 = Integer.parseInt(number1.getText().toString());
// num2 = Integer.parseInt(number2.getText().toString());
resultnum = Math.cos(Math.toDegrees(num1));
result.setText(String.valueOf(resultnum));
}
if (radient){
num1 = Integer.parseInt(number1.getText().toString());
//num2 = Integer.parseInt(number2.getText().toString());
resultnum = Math.cos(Math.toRadians(num1));
result.setText(String.valueOf(resultnum));
}
if (!degree)
{
}
if (!radient){
}
}
});
tand.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//TAN num2
if (degree)
{
num1 = Integer.parseInt(number1.getText().toString());
//num2 = Integer.parseInt(number2.getText().toString());
resultnum = Math.tan(Math.toDegrees(num1));
result.setText(String.valueOf(resultnum));
}
if (radient){
num1 = Integer.parseInt(number1.getText().toString());
// num2 = Integer.parseInt(number2.getText().toString());
resultnum = Math.tan(Math.toRadians(num1));
result.setText(String.valueOf(resultnum));
}
if (!degree)
{
}
if (!radient){
}
}
});
switch2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//switchR
radient = true;
degree = false;
textView8.setText(("Radians MODE"));
}
});
switch3.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//switchD
degree = true;
radient = false;
textView8.setText(("Degree MODE"));
}
});
}}
共 (0) 个答案