Android 神秘活动不符合应用程序主题
在安卓平台上开发了几个月之后,我仍然有一个未回答的问题。我很久以前就注意到,我有一个活动与应用程序主题的其余部分不一致。这意味着默认情况下,“活动”的字体颜色为白色(而非黑色),未选中时复选框不会显示,您根本看不到它们。非常奇怪的行为。最近,我更改了主题的colorAccent属性,将所有强调颜色更改为橙色(包括复选框),但此活动保持不变。有人经历过吗 我曾经把这个活动变成一个片段,然后它神奇地符合主题。切换回活动后,即使创建一个全新的活动来承载逻辑,也没有任何变化。以下是活动布局:Android 神秘活动不符合应用程序主题,android,android-activity,checkbox,themes,Android,Android Activity,Checkbox,Themes,在安卓平台上开发了几个月之后,我仍然有一个未回答的问题。我很久以前就注意到,我有一个活动与应用程序主题的其余部分不一致。这意味着默认情况下,“活动”的字体颜色为白色(而非黑色),未选中时复选框不会显示,您根本看不到它们。非常奇怪的行为。最近,我更改了主题的colorAccent属性,将所有强调颜色更改为橙色(包括复选框),但此活动保持不变。有人经历过吗 我曾经把这个活动变成一个片段,然后它神奇地符合主题。切换回活动后,即使创建一个全新的活动来承载逻辑,也没有任何变化。以下是活动布局: &
<?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>
有人知道为什么这项活动变得无赖吗
编辑:添加了清单
<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();
}
});
}
公共类ModifyActivity扩展AppCompative实现DeleteConfirmationDialog.DeleteConfirmationListener{
私有静态字符串LOG_TAG=ModifyActivity.class.getCanonicalName();
专用数据库助手数据库助手;
私人巴士供应商;
/**用户界面引用*/
私有进程对话;
文本视图标题;
private Obj selectedObj;//要编辑的对象
私有ModifyActivityListAdapter ModifyActivityListAdapter;
private ArrayList buddiesToAdd;//要添加的Buddies
private ArrayList buddiesToRemove;//要删除的好友
//允许这两个进程相互跟踪,并在两者都完成后返回buddies活动
私有布尔加法完成;
私有布尔删除完成;
采取的私人行动;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify);
busProvider=busProvider.getInstance();
databaseHelper=databaseHelper.getInstance(getApplicationContext());
title=(TextView)findViewById(R.id.title\u栏);
int id=Integer.valueOf(getIntent().getStringExtra(ConstantValues.IntentArguments.ARG_id));
//要编辑的对象
selectedObj=databaseHelper.selectObjWithId(id);
//if(selectedObj!=null){
//title.setText(selectedObj.getName());
// }
//获取所选obj的所有成员
arraylistmembersofselectedobj=databaseHelper.selectMembersOfObj(id);
//实例化
ListView editListView=(ListView)findViewById(R.id.edit\u ListView);
//创建适配器
modifyActivityListAdapter=新建modifyActivityListAdapter(getApplicationContext(),membersOfSelectedObj);
//连接适配器
setAdapter(modifyActivityListAdapter);
按钮doneButton=(按钮)findviewbyd(R.id.done\u编辑按钮);
按钮取消按钮=(按钮)findViewById(R.id.cancel\u编辑按钮);
ImageButton deleteButton=(ImageButton)findViewById(R.id.delete_按钮);
ImageButton重命名按钮=(ImageButton)findViewById(R.id.rename_按钮);
doneButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
analyzeUserInput(modifyActivityListAdapter.getAllBuddies());
}
});
cancelButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
onBackPressed();
}
});
deleteButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
createDeleteConfirmDialog();
}
});
重命名按钮.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图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>
在setContentView上使用的xml布局文件上,转到可视化设计部分,查看该窗口中的顶部标题。您可以通过单击“活动名称”选项卡左侧的按钮来设置主题。您是否检查过这是否是代码中的问题,例如列表中的视图持有者设计模式可能存在问题查看实现。由于适配器代码尚未发布,这是因为您如何构造您的ModifyActivityListAdapter
。您正在为其提供一个应用程序上下文,适配器使用该上下文来扩展其项视图。请改为尝试传递活动上下文
// Create adapter
modifyActivityListAdapter = new ModifyActivityListAdapter(this, membersOfSelectedObj);
默认情况下,应用程序上下文不包含主题信息。因此,使用它膨胀的视图将不会有您的自定义主题
当您在清单的中指定android:theme
时。这是从2013年开始的,但此后上下文并没有太大变化。您如何在manifest
文件中声明此活动