在Android平台开发数月后,我仍有一个未解决的问题。很久以前我就注意到只有一个Activity与应用程序主题不符合。这意味着默认情况下,Activity的字体颜色是白色(而不是黑色),当复选框未被选中时,它们不会显示出来,你根本看不到它们。非常奇怪的行为。最近,我改变了我的主题的colorAccent属性,将所有强调颜色都改成了橙色(包括复选框),但是这个Activity仍然没有改变。有人经历过这种情况吗?
我曾经将这个Activity制作成片段,然后它神奇地符合了主题。在切换回Activity后,即使创建一个全新的主机逻辑的Activity,仍然没有发生任何变化。以下是Activity布局:
我曾经将这个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();
}
});
}
编辑:发表列表项的代码,这是真正变色的东西。复选框应该是橙色的,字体应该是黑色的,但它们完全不可见(白色),所以我需要手动更改文本颜色。
<?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>
android:theme
属性声明的吗? - Satyen Udeshi