我需要调整此部件尺寸以完全显示.我怎样才能做到这一点?

我的适配器:
String[] navigations = getResources().getStringArray(R.array.actionBar);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.custom_spinner_title_bar,
android.R.id.text1, navigations);
adapter.setDropDownViewResource(R.layout.custom_spinner_title_bar);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(adapter, navigationListener);
Run Code Online (Sandbox Code Playgroud)
custom_spinner_title_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal"
android:orientation="vertical" >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我知道有两种方法可以在Android中设置标题Activity.
假设我已经有以下代码......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
...
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)
......我可以用这个......
getSupportActionBar().setTitle("My title");
Run Code Online (Sandbox Code Playgroud)
...或这个...
toolbar.setTitle("My title");
Run Code Online (Sandbox Code Playgroud)
......设定我的头衔.
我的问题是,哪种更好的做法?
我有一个片段,我尝试更改操作栏的标题.这一直有效,直到我添加setHasOptionsMenu(true)到片段中.我怎么解决这个问题?因为我需要optionsmenu片段中的.
在片段中
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
((MainActivity)getActivity()).setActionBarTitle(getString(R.string.title_view_tree));
setHasOptionsMenu(true);
return inflater.inflate(R.layout.fragment_view_tree, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_view_tree,menu);
super.onCreateOptionsMenu(menu,inflater);
}
Run Code Online (Sandbox Code Playgroud)
在MainActivity中:
public void setActionBarTitle(String title) {
getSupportActionBar().setTitle(title);
}
Run Code Online (Sandbox Code Playgroud)
当我setHasOptionsMenu(true)通过使用//然后actionbar正确使用更改的标题禁用.
android android-titlebar android-fragments android-actionbar
在我的Android应用程序中,我隐藏了默认标题栏,引入了TabView并在TabView的选项卡下添加了我自己的标题栏.目前,我正在使用?android:attr/windowTitleStyle样式,这使我的新标题栏显示为灰色和渐变.它看起来不错,但我的屏幕看起来非常灰度.我想通过使这个标题栏成为不同的颜色渐变来增加一些东西.
我在这看什么?创建我自己的图像并使用它??android:attr/windowTitleStyle样式似乎会根据自定义标题栏的高度进行扩展; 所以我不确定它实际上是一个单一的图像.
我尝试用一点半透明的方式抛出一个LinearLayout(例如:使颜色为#800000FF),但我在此LinearLayout后面的渐变样式消失了.
谢谢你的帮助
更新:
根据我在下面的回答,我发现我可以创建一个定义渐变的XML文件并使用它.它在我的布局上的LinearLayout(titlebar_gradient)中工作正常.但是,它不适用于最外层的LinearLayout(background_gradient).有人能告诉我为什么吗?据我了解,ListView应该是透明的......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_gradient"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="47dip"
android:background="@drawable/titlebar_gradient"
android:gravity="center">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Item"
style="?android:attr/windowTitleStyle"
android:paddingLeft="5dip"
android:maxLines="1"
android:ellipsize="end" />
</LinearLayout>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dip"
android:clickable="false"
/>
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 到目前为止,我发现的所有用于更改活动标题栏颜色的解决方案(即通过activity.setTitle()和activity.setProgress()访问的解决方案)都要求FEATURE_CUSTOM_TITLE:
但我已经在使用FEATURE_PROGRESS和Android禁止将自定义标题与其他标题功能相结合(通过AndroidRuntimeException),我不想放弃那个很好的进度条,这是我活动中不可或缺的一部分.
关于在没有FEATURE_CUSTOM_TITLE的情况下更改活动标题栏颜色的唯一提示是在另一个SO线程中:
View titleView = getWindow().findViewById(android.R.id.titlebar);
if (titleView != null) {
ViewParent parent = titleView.getParent();
if (parent != null && (parent instanceof View)) {
View parentView = (View)parent;
parentView.setBackgroundColor(Color.RED);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试按原样使用代码,则android.R.id.titlebar无法解决!
我在哪里找到的android.R.id.titlebar?
我必须自己定义吗?(如果答案是肯定的,这本质上不是FEATURE_CUSTOM_TITLE吗?)
在清单文件中,我将此行添加到我的应用程序标记中
android:theme="@android:style/Theme.NoTitleBar"
Run Code Online (Sandbox Code Playgroud)
基本上每个活动都没有标题栏,但是对于我希望显示标题栏的其中一个活动
我知道要隐藏栏我可以使用此代码
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)
如何从代码中显示标题栏?
编辑 请不要高我怎么能隐藏标题栏:),我知道,如果有人知道我怎么能显示它?
我知道我可以把NoTitleBar放在我想要隐藏的每个活动中,我可以把它留给我想要展示的那个......但那不是我的观点
android titlebar android-titlebar android-theme android-activity
我已经将我的活动主题设置为android:theme ="@ android:style/Theme.Dialog"但我也想删除活动的标题栏.那么如何使用android:theme ="@ android:style/Theme.Black.NoTitleBar.Fullscreen"以及对话框主题.
android coding-style android-sdk-2.1 android-titlebar android-theme
Android开发人员参考列出了可用的内置View资源中的R.id.progress.
然而,当我发布(在我的活动类中)声明时:
View pv = getWindow().findViewById(android.R.id.progress);
Run Code Online (Sandbox Code Playgroud)
它返回null.
即使我将它与ProgressBar类一起使用它也会返回null :
ProgressBar pv = (ProgressBar) getWindow().findViewById(android.R.id.progress);
Run Code Online (Sandbox Code Playgroud)
即使没有getWindow(),它也会返回null :
ProgressBar pv = (ProgressBar) findViewById(android.R.id.progress);
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
为了确保我没有产生幻觉,我按照@ Geobits的建议从头开始创建了一个新项目,其中包含@ArunGeorge推荐的博客文章中列出的确切代码:
package com.droidworks;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
public class ProgressBarExampleActivity extends Activity {
private ProgressBar mProgress;
private MyThread mBgThread;
private final Handler mHandler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mProgress = (ProgressBar) findViewById(android.R.id.progress);
mBgThread = (MyThread) …Run Code Online (Sandbox Code Playgroud) android android-titlebar android-progressbar android-resources
在我扩展FragmentActivity类的活动中,我无法使用禁用标题this.requestWindowFeature(Window.FEATURE_NO_TITLE);.它给出了一个ANR.
如何禁用FragmentActivity的标题?
这是活动开始的部分代码:
public class NewOrderActivity extends FragmentActivity implements TabListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
...
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:答案:
好吧,我发现在一个已经在其中声明了ActionBar的活动中,标题是Action Bar的一部分而不是windows本身.
所以在我的代码中,我这样做是为了摆脱窗口(或更好地说,ActionBar的)标题:
...
...
final ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(Window.FEATURE_NO_TITLE);
...
...
Run Code Online (Sandbox Code Playgroud) 我已经在onCreate()方法中删除了标题.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)

标题不显示.但是在启动应用程序时仍会出现.

我可以使用
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)
或者说
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)
进入清单文件,因为我正在使用actionBar.如果我这样做,应用程序崩溃.
所以,我的问题是,有没有办法在应用程序启动时删除标题,因为我要在这里放一个闪屏.谢谢.
请注意:
谢谢你的回答,但我清楚地说我已经习惯actionBar.setDisplayShowTitleEnabled(false);
隐藏活动的标题栏.(如第一张图片所示)
但标题栏仍然出现在启动屏幕中(如第二张图所示).
和
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)
和
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)
会导致崩溃发射.这是在我使用动作栏后发生的.