您好我正在使用演示应用程序,我需要ActionBar在其中心设置标题.我已经尝试了一些不适合我的SO帖子.我正在试用Android 4.3手机.
/sf/answers/1523937411/,/sf/answers/1347124341/
但没有什么对我有用.有没有办法ActionBar在Android中使用appcompat 设置中心标题?
我这样做就像下面但仍然标题在左侧.
center_action_bar_title.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
Run Code Online (Sandbox Code Playgroud)
在活动中
TextView customView = (TextView)
LayoutInflater.from(getActivity()).inflate(R.layout.center_action_bar_title,
null);
ActionBar.LayoutParams params = new
ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
customView.setText(text);
((ActionBarActivity)getActivity()).getSupportActionBar().setCustomView(customView, params);
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-actionbar android-actionbar-compat
我不能让新的棒棒糖抽屉切换工作.
我这样做了:
void setupToolbar() {
setToolbarAsActionBar();
setupDrawerToggle();
}
public void setToolbarAsActionBar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
void setupDrawerToggle() {
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.overview_title, R.string.overview_title) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
drawerLayout.setDrawerListener(drawerToggle);
drawerToggle.setDrawerIndicatorEnabled(true);
drawerToggle.syncState();
}
Run Code Online (Sandbox Code Playgroud)
汉堡包图标在那里,我看到通过滑动手指滑出抽屉的动画.但是,图标无法点击.我错过了什么?
android android-appcompat android-5.0-lollipop android-toolbar
我在AppCompat Actionbar中包含了一个SearchView,但它的图标总是有阴影.
对于其他图标,我使用Android下载页面中没有阴影的图标,实际上我也尝试为SearchView直通分配图标android:icon="@drawable/ic_action_search"但不会更改图标.

我的研究告诉我,实际上ab_ic_search.png来自android-support-v7-appcompat.jar正在被使用而我android:icon="@drawable/ic_action_search"被忽略了.
我尝试了各种各样的方法,比如尝试替换图像onPrepareOptionsMenu(通过尝试查找ImageView)或通过自定义子类SearchView但无效.
任何想法如何解决?基本上我只想让我的图标统一,我是否必须为所有其他图标添加阴影?可能我无论如何都无法为那些"三个点"添加阴影?
我AppCompat在教会应用程序中使用库,但我的菜单图标没有出现ActionBar.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
case R.id.menu_item_share:
shareApp();
return true;
case R.id.menu_item_about:
Intent intentAbout = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intentAbout);
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习android材质设计。使用工具栏,我想更改弹出菜单以及文本颜色。所以我发现可以通过添加以下代码来完成
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CCC"
app:theme="@style/ThemeOverlay.AppCompat.Light"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
android:elevation="4dp"
>
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
但是问题是app:theme和app:popupTheme无法正常工作,并且在android studio xml文件中显示错误。
我能知道些什么?
我正在使用com.android.support:appcompat-v7:23.0.0
在我使用支持库v7的应用程序中,我想添加一个首选项屏幕.由于Google完全没有提供有关该主题的文档,因此我查找了Stack Overflow上其他地方发现的帖子.
所以这是我的项目:
activity_preferences.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:support="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar_default"/>
<fragment
android:name=".FragmentPreferences"
name=".FragmentPreferences"
android:tag=".FragmentPreferences"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
ActivityPreferences.java
package com.example.testandroidsupportv7;
import com.example.testandroidsupportv7.R;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class ActivityPreferences extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
}
}
Run Code Online (Sandbox Code Playgroud)
FragmentPreferences.java
package com.example.testandroidsupportv7;
import com.example.testandroidsupportv7.R;
import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;
public class FragmentPreferences extends PreferenceFragmentCompat
{
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<activity
android:name=".ActivityPreferences"
android:label="@string/app_name"
android:theme="@style/MyTheme.NoActionBar" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-preferences android-support-library