2013-02-11 110 views
0

我正在升級我的應用以包含操作欄,我對格式有點困惑。顏色問題(Android)

所以第一個活動看起來不錯,這裏是代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/main_title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/main_title" 
    android:textSize="24sp" 
    android:textColor="@color/orange" 
    android:textStyle="bold" 
    android:gravity="center_vertical|center_horizontal" 
    android:padding="20dp"/> 
    <Button 
    android:id="@+id/new_inspection" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/main_title" 
    android:text="@string/create_new_inspection"/> 
    <TextView 
    android:id="@+id/saved_inspections" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/new_inspection" 
    android:text="@string/saved_inspections" 
    android:padding="5dp"/> 
    <ListView 
    android:id="@id/android:list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/saved_inspections"/> 
    <TextView 
    android:id="@id/android:empty" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/no_saved_inspections" 
    android:gravity="center" 
    android:padding="20dp" 
    android:layout_below="@id/saved_inspections"/> 
</RelativeLayout> 

的onCreate方法本:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_inspection); 
    setUpViews(); 
    setLongClick(); 
    rmDbHelper = new RMDbAdapter(this); 
    rmDbHelper.open(); 
    Cursor listCursor = rmDbHelper.fetchAllInspections(); 
    startManagingCursor(listCursor);   
    setListAdapter(new MyListAdapter(this, listCursor)); 
} 

,看起來像這樣:

Correct layout

但其他一些活動不是這樣,我不知道爲什麼 - 例如,這裏是下一個活動代碼:它看起來像這樣

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_run); 
    rmDbHelper = new RMDbAdapter(this); 
    rmDbHelper.open(); 
    Intent i = getIntent(); 
    inspectionId = i.getLongExtra("Intent_InspectionID", -1); 
    areaId = i.getLongExtra("Intent_AreaID", -1); 
    setUpViews(); 
    setLongClick(); 
    Cursor listCursor = rmDbHelper.fetchAllRunsForArea(areaId); 
    startManagingCursor(listCursor);   
    setListAdapter(new MyListAdapter(this, listCursor)); 
} 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<RelativeLayout 
android:id="@+id/heading_layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 
    <TextView 
    android:id="@+id/main_title" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/main_title" 
    android:textSize="18sp" 
    android:textStyle="bold" 
    android:textColor="@color/orange" 
    android:gravity="center_vertical|center_horizontal" 
    android:padding="5dp"/> 
    <TextView 
    android:id="@+id/secondary_title" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/main_title" 
    android:text="@string/secondary_title" 
    android:textStyle="bold" 
    android:gravity="center_vertical|center_horizontal" 
    android:padding="5dp"/> 
    <Button 
    android:id="@+id/new_run" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/secondary_title" 
    android:text="@string/create_new_run"/> 
    <TextView 
    android:id="@+id/saved_runs" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/new_run" 
    android:text="@string/saved_runs" 
    android:padding="5dp"/> 
</RelativeLayout> 

<LinearLayout 
android:id="@+id/complete_button_layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true"> 
    <Button 
    android:id="@+id/complete_button" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/run_area_complete" 
    android:padding="5dp"/> 
</LinearLayout> 

<ListView 
android:id="@id/android:list" 
android:layout_width="fill_parent" 
android:layout_height="0dp" 
android:layout_below="@id/heading_layout" 
android:layout_above="@id/complete_button_layout"/> 
<TextView 
android:id="@id/android:empty" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/no_saved_runs" 
android:layout_centerHorizontal="true" 
android:padding="20dp" 
android:layout_below="@id/heading_layout" 
android:layout_above="@id/complete_button_layout"/> 

</RelativeLayout> 

的OnCreate此

Incorrect layout

的顏色是遍佈該店和我看不到在xml文件中有所不同..

下面是信息清單:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.scamparelli.rm" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="11" 
    android:targetSdkVersion="16" /> 

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

<application 
    android:icon="@drawable/logo" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Holo" > 
    <activity 
     android:name=".InspectionActivity" 
     android:screenOrientation="portrait" 
     android:windowSoftInputMode="adjustResize" 
     android:label="@string/title_activity_inspection" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name=".InspectionEdit" 
     android:screenOrientation="portrait" 
     android:windowSoftInputMode="adjustResize"/> 
    <activity android:name=".AreaActivity" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".AreaEdit" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".RunActivity" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".RunEdit" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".LocationActivity" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".ComponentEdit" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".IssueActivity" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".IssueEdit" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".SpecificationEdit" 
     android:screenOrientation="portrait"/> 
    <activity android:name=".ExportActivity" 
     android:screenOrientation="portrait"/> 

</application> 

</manifest> 
+0

你在使用Android清單中的主題嗎? – StarsSky 2013-02-11 12:42:37

+0

我認爲背景顏色有什麼問題 – 2013-02-11 12:45:36

+0

第二頁上的按鈕看起來像是被禁用了,而不是主題。 – paul 2013-02-11 12:45:45

回答

-2

只需設置父佈局的背景顏色以黑色爲:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@android:color/black"> 

,或者設置應用主題:

Theme.Black.NoTitleBar 

比希望它看起來很好。

+0

不要以爲這是答案Manoj - 我需要設置主題以光暈獲取操作欄添加.. – Scamparelli 2013-02-11 12:56:32