我正在开发我的第一个Android项目 - 一个简单的活动应用程序本质上是信息性的。在Android工作室中,我将主题设置为素材灯光,我的Android布局将两个TextViews对齐。图1显示了它在Android Studio中的外观。但是,每当我在模拟器或Android设备上运行它时,我在图像2中得到以下内容。文本左对齐而右对齐,主题从白色变为紫色。
所以......发生了什么事?这是一个非常简单的应用程序。下面是我的布局的XML,以便于参考。
>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/appbg"
/>
<TextView
android:id="@+id/headingNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:fontFamily="@font/abril_fatface"
android:textSize="32sp"
android:padding="16sp"
android:layout_margin="8sp"
android:text="JR's Pizza Call
817-297-3000"
android:textColor="#9e0f17"
/>
<TextView
android:id="@+id/mainTextInfo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_below="@id/headingNumber"
android:textAlignment="viewEnd"
android:padding="16sp"
android:layout_margin="16sp"
android:text="For the best pizza in Crowley, Texas try JR's Pizza. If you like pepperoni pizza, or pizza with the works, a supreme pizza, or a cheese pizza, JR's Pizza Crowley is here for you. If you like real beef hamburgers you've come to the right place. Or maybe you're in the mood for a fresh salad, pasta, or one of our delicious burritos, we have those on the menu too."
/>
</RelativeLayout>
编辑我的代码:
<TextView
android:id="@+id/headingNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:fontFamily="@font/abril_fatface"
android:textSize="42sp"
android:textAlignment="viewEnd"
android:padding="16sp"
android:layout_margin="8sp"
android:text="JR's Pizza Call
817-297-3000"
android:textColor="#9e0f17"
/>
<TextView
android:id="@+id/mainTextInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textAlignment="viewEnd"
android:layout_below="@id/headingNumber"
android:padding="16sp"
android:layout_margin="16sp"
android:text="For the best pizza in Crowley, Texas try JR's Pizza. If you like pepperoni pizza, or pizza with the works, a supreme pizza, or a cheese pizza, JR's Pizza Crowley is here for you. If you like real beef hamburgers you've come to the right place. Or maybe you're in the mood for a fresh salad, pasta, or one of our delicious burritos, we have those on the menu too."
/>
答案 0 :(得分:2)
将以下属性添加到左对齐的TextView
:
android:layout_alignParentRight="true"
同样,如果ActionBar
的颜色与Android Studio中的颜色相似,则可以在styles.xml
文件夹中进行更改,它们称为colorPrimary
和{{1} }。