【发布时间】:2015-12-30 22:28:14
【问题描述】:
在 Android 平台上开发数月后,我仍有一个未解决的问题。很久以前我注意到我有一个不符合应用程序主题其余部分的单一活动。这意味着默认情况下,Activity 的字体颜色是白色(不是黑色),并且 Checkboxes 不勾选时不显示,你根本看不到它们。非常奇特的行为。最近,我更改了我的主题的 colorAccent 属性,将所有强调色更改为橙色(包括 Checkboxes),但这个 Activity 保持不变。有人经历过吗?
我曾经把这个 Activity 做成一个片段,然后它神奇地符合主题。切换回 Activity 后,即使创建一个全新的 Activity 来承载逻辑,也没有任何改变。这是活动布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
>
<android.support.design.widget.AppBarLayout android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.core.utility.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="24sp"
android:id="@+id/title_bar"
android:textColor="@android:color/white"
android:text="Edit"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/appbar"
android:id="@+id/listview"
android:scrollbars="none"
android:layout_above="@+id/buttons_layout"
android:layout_gravity="center_horizontal|top"
/>
<LinearLayout
android:weightSum="2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="@android:color/transparent"
android:id="@+id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCEL"
android:layout_weight="1"
android:layout_margin="@dimen/activity_vertical_margin"
android:id="@+id/cancel_editing_button"
android:background="@drawable/custom_button_logout"
android:textColor="@android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DONE"
android:layout_weight="1"
android:layout_margin="@dimen/activity_vertical_margin"
android:id="@+id/done_editing_button"
android:background="@drawable/custom_button_logout"
android:textColor="@android:color/white"
/>
</LinearLayout>
</RelativeLayout>
这是这一切的样子:
有没有人知道为什么这个 Activity 变得流氓了??
编辑:添加清单
<application
tools:replace="android:icon"
android:allowBackup="true"
android:icon="@mipmap/ic_trans2"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:name=".utility.AppInit"
>
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="software.gcm" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
<!-- [START gcm_listener] -->
<service
android:name=".gcm.GcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
<!-- [START instanceID_listener] -->
<service
android:name=".gcm.InstanceIDListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<!-- [END instanceID_listener] -->
<!-- [START registration_service] -->
<service
android:name=".gcm.RegistrationIntentService"
android:exported="false" >
</service>
<!-- [END registration_service] -->
<!-- [START application activities] -->
<activity
android:name=".userinterface.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".session.InitSessionActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".userinterface.ProfileActivity"
android:label="@string/title_activity_profile"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="me.core.userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.AddBuddyActivity"
android:label="Add Buddy"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.ModifyActivity"
android:label=""
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.BuddyRequestsActivity"
android:label=""
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.ThreadDetailsActivity"
android:label="@string/title_activity_messages"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<!-- [END application activities] -->
</application>
编辑:添加来源
public class ModifyActivity extends AppCompatActivity implements DeleteConfirmationDialog.DeleteConfirmationListener {
private static String LOG_TAG = ModifyActivity.class.getCanonicalName();
private DatabaseHelper databaseHelper;
private BusProvider busProvider;
/** UI references*/
private ProgressDialog progressDialog;
TextView title;
private Obj selectedObj; // The obj to be edited
private ModifyActivityListAdapter modifyActivityListAdapter;
private ArrayList<Buddy> buddiesToAdd; // Buddies to be added
private ArrayList<Buddy> buddiesToRemove; // Buddies to be removed
// Allows these two processes to keep track of one another, and go back to buddies activity when both are done
private boolean additionDone;
private boolean deletionDone;
private boolean actionTaken;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify);
busProvider = BusProvider.getInstance();
databaseHelper = DatabaseHelper.getInstance(getApplicationContext());
title = (TextView)findViewById(R.id.title_bar);
int id = Integer.valueOf(getIntent().getStringExtra(ConstantValues.IntentArguments.ARG_ID));
// The object to be edited
selectedObj = databaseHelper.selectObjWithId(id);
// if (selectedObj!=null) {
// title.setText(selectedObj.getName());
// }
// Get all members of chosen obj
ArrayList<Member> membersOfSelectedObj = databaseHelper.selectMembersOfObj(id);
//Instantiate
ListView editListView = (ListView)findViewById(R.id.edit_listview);
// Create adapter
modifyActivityListAdapter = new ModifyActivityListAdapter(getApplicationContext(), membersOfSelectedObj);
// Attach adapter
editListView.setAdapter(modifyActivityListAdapter);
Button doneButton = (Button)findViewById(R.id.done_editing_button);
Button cancelButton = (Button)findViewById(R.id.cancel_editing_button);
ImageButton deleteButton = (ImageButton)findViewById(R.id.delete_button);
ImageButton renameButton = (ImageButton)findViewById(R.id.rename_button);
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
analyzeUserInput(modifyActivityListAdapter.getAllBuddies());
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createDeleteConfirmDialog();
}
});
renameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createRenameConfirmDialog();
}
});
}
EDIT:列表项的发布代码,这是真正变色的东西。复选框应为橙色,字体为黑色,但它们显示为完全不可见(白色),因此我需要手动更改文本颜色。
<?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="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:minHeight="?android:attr/listPreferredItemHeight"
tools:context=".userinterface.ModifyActivity"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:text="howdy"
android:textColor="@android:color/black"
android:textSize="20sp"
android:layout_centerVertical="true"
android:id="@+id/edit_list_item_textview"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shadowColor="@color/lb_orange"
android:layout_centerVertical="true"
android:id="@+id/edit_list_item_checkbox"
android:focusable="false"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
【问题讨论】:
-
你是如何在你的
manifest文件中声明这个Activity的,意思是用android:theme属性声明的? -
是的,它已经被声明并且 Manifest 主题已经设置好了。
-
您可以添加您的
Manifest吗? -
已添加,有问题的活动是 ModifyActivity
-
添加有问题的样式代码
标签: android android-activity checkbox themes