相关疑难解决方法(0)

Android:如何在ToolBar中居中标题

我第一次在我的项目中使用ToolBar,所以我不知道如何在android中自定义工具栏.我需要将标题集中到工具栏中,如何做到这一点请告诉我.

预先感谢.

android toolbar

17
推荐指数
9
解决办法
8万
查看次数

中心使用android中的样式在操作栏中对齐标题.

嗨,我正在开发Android应用程序.在我的应用程序中,我正在使用操作栏.我想让中心在动作栏中对齐我的窗口标题.我知道可以使用xml文件.但我想用风格来做它,以便它适用于我的每个窗口,如何做到这一点需要帮助.谢谢.

android title center-align android-actionbar

16
推荐指数
3
解决办法
5万
查看次数

如何让android动作栏标题中心对齐?

我尝试了自己的自定义操作栏,让操作栏标题位于中间位置.有效.但是,在我添加操作栏中的选项菜单后,标题再次向左移动.我应该怎么做才能让标题集中在动作栏的中间?我的代码是:

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);    
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    View cView = getLayoutInflater().inflate(R.layout.custom_actionbar, null);
    actionBar.setCustomView(cView);
Run Code Online (Sandbox Code Playgroud)

我的布局是

<?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:layout_gravity="center"
android:background="@android:color/holo_blue_light"
android:orientation="vertical" >

<TextView
    android:id="@+id/apptitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_gravity="center_horizontal|center_vertical"
    android:gravity="center_horizontal|center_vertical"
    android:text="@string/app_name" />
Run Code Online (Sandbox Code Playgroud)

android center android-actionbar

10
推荐指数
1
解决办法
3万
查看次数

如何在活动中对齐标题或标签的中心?

我知道有两种设置活动标题的方法.一种方法是在android清单中设置它,如android:label ="@ string/app_name".第二个是在活动类中以编程方式设置,如setTitle("Hello World!").两种方式都位于左侧,但我如何将其放在中心?

android label title android-activity

6
推荐指数
4
解决办法
5万
查看次数

为什么应用程序名称未显示在 Android 的工具栏中?

应用程序名称未显示在应用程序栏中。它的白色。我不知道为什么。请帮忙。之前有显示。然后我做了很多改变现在无法修复它

在主要活动中

....
<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    android:visibility="visible"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


  ....

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在样式中

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在安卓清单中

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    >
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

public class MainActivity extends AppCompatActivity  {

    public static final String LOG_TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) …
Run Code Online (Sandbox Code Playgroud)

java android

5
推荐指数
1
解决办法
3495
查看次数

Android:如何集中活动标签

我想让标签(我的应用程序)在操作栏中集中对齐.我应该怎么做?

这是当前的屏幕:

主屏幕

android label android-actionbar

2
推荐指数
1
解决办法
7684
查看次数

如何在不使用自定义视图的情况下将操作栏标题对齐到中心

我想在没有自定义视图帮助的情况下将操作栏标题对齐到中心。我将不胜感激任何帮助。

不使用自定义视图,只修改默认操作栏标题

android android-actionbar

2
推荐指数
1
解决办法
1万
查看次数

如何在Android中设置操作栏的标题

您好我正在使用演示应用程序,我需要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

0
推荐指数
1
解决办法
5990
查看次数