Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在ActionBar中是否有最多可存储的图标数?_Android_Android Actionbar_Actionbarsherlock - Fatal编程技术网

Android 在ActionBar中是否有最多可存储的图标数?

Android 在ActionBar中是否有最多可存储的图标数?,android,android-actionbar,actionbarsherlock,Android,Android Actionbar,Actionbarsherlock,我目前有4个动作在我的动作栏,它切断了屏幕的标题。我知道我可以使用android:uiOptions=“splitActionBarWhenNarrow”添加底部栏,但我想知道是否可以将动作图标缩小?我也知道我可以使用ActionOverflow选项,但如果可能的话,我会尽量避免。如果没有,底部是否有一个最大值,顶部是否有一个最大值 编辑 另外,是否有类似于setTitleTextSize()的调用?也许如果我能把我的标题改小一点,它会有用的,但是我在网站上找不到任何东西。没有谷歌批准的方法可以

我目前有4个动作在我的动作栏,它切断了屏幕的标题。我知道我可以使用android:uiOptions=“splitActionBarWhenNarrow”添加底部栏,但我想知道是否可以将动作图标缩小?我也知道我可以使用
ActionOverflow
选项,但如果可能的话,我会尽量避免。如果没有,底部是否有一个最大值,顶部是否有一个最大值

编辑


另外,是否有类似于
setTitleTextSize()
的调用?也许如果我能把我的标题改小一点,它会有用的,但是我在网站上找不到任何东西。

没有谷歌批准的方法可以做到这一点,但是这个小技巧应该会有用

try {
    final int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView title = (TextView) getWindow().findViewById(titleId);
    // check for null and manipulate the title as you see fit
} catch (Exception e) {
    Log.e(TAG, "Failed to obtain action bar title reference");
}
不过,谷歌认可的一种稍微好一点的方法是在ActionBar上设置一个自定义布局:

您可以为动作栏使用自定义视图(它将显示在图标和动作项之间)。我正在使用自定义视图,并且禁用了本机标题。我的所有活动都继承自单个活动,该活动的onCreate中包含以下代码:

this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);

LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.titleview, null);

//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());

//assign the view to the actionbar
this.getActionBar().setCustomView(v);
布局xml(上面代码中的R.layout.titleview)应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:textSize="20dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:text="" />
</RelativeLayout>


更改android:textSize=“20dp”以更改标题的大小。

没有谷歌批准的方法可以做到这一点,但这一小技巧应该可以奏效

try {
    final int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView title = (TextView) getWindow().findViewById(titleId);
    // check for null and manipulate the title as you see fit
} catch (Exception e) {
    Log.e(TAG, "Failed to obtain action bar title reference");
}
不过,谷歌认可的一种稍微好一点的方法是在ActionBar上设置一个自定义布局:

您可以为动作栏使用自定义视图(它将显示在图标和动作项之间)。我正在使用自定义视图,并且禁用了本机标题。我的所有活动都继承自单个活动,该活动的onCreate中包含以下代码:

this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);

LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.titleview, null);

//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());

//assign the view to the actionbar
this.getActionBar().setCustomView(v);
布局xml(上面代码中的R.layout.titleview)应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:textSize="20dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:text="" />
</RelativeLayout>


更改
android:textSize=“20dp”
以更改标题的大小。

这将因设备而异,具体取决于屏幕大小。好了,API中没有任何东西会告诉你这一点。我想是的,谢谢。您知道如何更改标题文本大小吗?不,您不能更改标题文本大小。您可以创建自定义的ActionBar布局并缩小标题和图标,但我不建议这样做,因为这会导致不一致。这将因设备而异,具体取决于屏幕大小。好了,API中没有任何东西会告诉你这一点。我想是的,谢谢。您知道如何更改标题文本大小吗?不,您不能更改标题文本大小。您可以创建一个自定义的ActionBar布局,并使标题和图标变小,但我不建议这样做,因为这会导致不一致。